2016-10-14 8 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フォームビューの親が起動している間にイベントを持つことが可能ではないでしょうか?

はあなたの助けをありがとう:)

+2

'init'に' self.userInteractionEnabled = YES; 'がありませんか? – Larme

+0

@Larme userInteractionEnabledは、デフォルトではYESです。 –

+1

'UIImageView'にないか、それは新しいです。 – Larme

答えて

0

あなたはUIImageViewは、サブビューのような追加プロパティでUIImageViewのカスタムクラスを作成しているmmmhhh。どうして? 「self」だけを使用してください。

UIImageViewに別のものの下にあるタップジェスチャーを追加しているため、これは機能しません。

+0

しかし、正義の "自己"は働いていません。私は理解していない、UIImageViewなしで動作しています。 :/カスタムクラスでタッチを使用するために何をすべきか? – silver

+0

自己とそれは動作していないのですか?どうして?あなたはその場合何をしましたか? – Larme

関連する問題