UITapGestureRecognizerがUIViewControllerのUIImageViewクラスで動作しません。UITapGestureRecognizerがUIImageViewカスタムクラスで動作しない
HousePictureView *pictureHouse = [[HousePictureView alloc] init:[dictionary objectForKey:@"photo_url"]];
UITapGestureRecognizer *picturestap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showpictures)];
picturestap.numberOfTapsRequired = 1;
[pictureHouse addGestureRecognizer:picturestap];
[parentScroll addSubview:pictureHouse];
HousePictureView.m
@interface HousePictureView() {
CGFloat screenwidth;
}
@property (strong, nonatomic) UIImageView *pictureView;
@end
@implementation HousePictureView
-(id)init:(NSString*)url
{
screenwidth = [UIScreen mainScreen].bounds.size.width; // Width of this screen
if(self = [super init])
{
_pictureView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,screenwidth,300)];
[_pictureView setImageWithURL:[NSURL URLWithString:url] placeholderImage:[Functions resizeImage:[UIImage imageNamed:@"nophoto"] newSize:CGSizeMake(screenwidth,300)]];
_pictureView.userInteractionEnabled = YES;
[self addSubview:_pictureView];
}
return self;
}
@end
HousePictureView.h
@interface HousePictureView : UIImageView
- (id)init:(NSString*)url;
@end
なぜそれがuserInteractionEnabledフォームビューの親が起動している間にイベントを持つことが可能ではないでしょうか?
はあなたの助けをありがとう:)
'init'に' self.userInteractionEnabled = YES; 'がありませんか? – Larme
@Larme userInteractionEnabledは、デフォルトではYESです。 –
'UIImageView'にないか、それは新しいです。 – Larme