2012-01-20 16 views
1

我正在UIScrollView上嘗試這段代碼,但它不工作。 NSLog沒有出現在我的控制檯上。怎麼了?它的工作很好,當它不在UIScrollView。Objective C:UILongPressGesture on ScrollView

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    [self papers]; 

    UIGestureRecognizer *recognizer = [[ UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; 
    longPressGR = (UILongPressGestureRecognizer *)recognizer; 
    longPressGR.minimumPressDuration = 0.5; 
    [Image1 addGestureRecognizer:longPressGR]; 
} 

-(void) handleLongPress:(UILongPressGestureRecognizer *)recognizer { 

    NSLog(@"Long Press"); 
} 
+0

這就像是某個班級的作業嗎? 2人問同樣的問題哈哈。 http://stackoverflow.com/questions/8937458/objective-c-uilongpressgesturerecognizer-error – Altealice

+0

哈哈!是啊,也許你看到我的朋友拉米羅。我們正試圖自己解決這個問題。 – SeongHo

回答

2

你沒有說出Image1是什麼。我猜一個UIImageView,在這種情況下,你需要確保你做:

[Image1 setUserInteractionEnabled:YES]; 

(不像大多數的意見,UIImageView的已交互默認禁用)。

(順便說一句,這是傳統的Objective-C讓你的ivars和方法以小寫字母開頭;類以大寫字母開頭。)