Basit UIView için jest tanıyıcı yapmak triyng ediyorum: Ben bakış mülkiyet gestureRecognizers debugUITapGestureRecognizer bir UIView'e eklenmedi mi?
UIView *theView = [[UIView alloc] initWithFrame:rect];
[theView setUserInteractionEnabled:YES];
UITapGestureRecognizer *tap = [[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleTap)] autorelease];
[theView addGestureRecognizer:tap];
o jest tanıyıcı nesneyi gösterir. Ancak manzaraya dokunduğumda işe yaramıyor.
Bir UIImageView kullanarak aynı kod mükemmel çalışır, neden herhangi bir fikir UIView'de çalışmaz?
GÜNCELLENEN:
Örnek bir sınıf.
@implementation ExampleClass
- (UIView *)getViewInRect:(CGRect)rect
{
UIView *theView = [[UIView alloc] initWithRect:rect];
[theView setUserInteractionEnabled:YES];
UITapGestureRecognizer *tap = [[[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleTap)]
autorelease];
[aText addGestureRecognizer:tap];
return theView;
}
- (UIImageView *)getImageViewInRect:(CGRect)rect
{
UIImageView *theView = [[UIImageView alloc] initWithRect:rect];
[theView setUserInteractionEnabled:YES];
UITapGestureRecognizer *tap = [[[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleTap)]
autorelease];
[theView addGestureRecognizer:tap];
return [theView autorelease];
}
- (void)handleTap
{
NSLog(@"Tap Handled!!", nil);
}
@end
2 GÜNCELLEME: theView tüm subviews için UITapGestureRecognizer ekleme
sorunu çözmek değil ...
FIX IT !!!
Tamam !! Sorun theView için CGRect oldu, genişlik 0.0 olarak ayarlandı!
handleTap işleviniz nasıl görünüyor? Görüntüleme'nin Süper Görünümünde bir jestRecognizer kullanıyorsunuz, bu da hareketi yakalayabilir mi? – Seega
handleTap, yukarıdaki kodun bulunduğu aynı sınıfın bir yöntemidir. Bu kepçeden [self handleTap] ile problemsiz olarak diyebilirim. –
Eğer 'UIView' yerine kod snippet'inde UIImageview' ile değiştirirseniz bunun işe yaradığını mı söylüyorsunuz? – freespace