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形式觀點父母被激活,有一個事件?
謝謝您的幫助:) mmmhhh您已經創建了一個自定義的UIImageView類的UIImageView像添加一個子視圖屬性
缺少'self.userInteractionEnabled = YES;'in'init'? – Larme
@Larme userInteractionEnabled默認爲YES。 –
不在'UIImageView'上,或者這是新的。 – Larme