2011-03-30 20 views
5

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ı!

+0

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

+0

handleTap, yukarıdaki kodun bulunduğu aynı sınıfın bir yöntemidir. Bu kepçeden [self handleTap] ile problemsiz olarak diyebilirim. –

+1

Eğer 'UIView' yerine kod snippet'inde UIImageview' ile değiştirirseniz bunun işe yaradığını mı söylüyorsunuz? – freespace

cevap

2

Görüntüyü .var dosyası olarak ivar olarak bildirin. Sentezleyin ve sonra böyle diyoruz:

[self.theview setMultipleTouchEnabled:YES]; 

viewDidLoad yönteminde theview alloc ve init unutmayın.

İşte bu kadar.

+1

Sorunu çözme, üzgünüm :-( –

19

Bunu denediniz mi?

[view setUserInteractionEnabled:YES]; 
İlgili konular