2016-10-14 55 views
0

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像添加一個子視圖屬性

+2

缺少'self.userInteractionEnabled = YES;'in'init'? – Larme

+0

@Larme userInteractionEnabled默認爲YES。 –

+1

不在'UIImageView'上,或者這是新的。 – Larme

回答

0

。爲什麼? 只需使用「自我」。

它不起作用,因爲您正在另一個UIImageView上添加點按手勢。

+0

但正當使用「自我」不起作用。我不明白,沒有UIImageView正在工作。 :/在自定義類中使用觸摸怎麼辦? – silver

+0

隨着自己它不工作?爲什麼?在這種情況下你做了什麼? – Larme

相關問題