2011-07-09 87 views
0

有一種方法只能在特定項目上劃過滑動界限?Delimit UISwipeGestureRecognizer

這樣它的工作原理無處不在

UIGestureRecognizer *recognizer; 

//RIGHT 
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)]; 
self.swipeRightRecognizer =(UISwipeGestureRecognizer *)recognizer; 
swipeRightRecognizer.direction = UISwipeGestureRecognizerDirectionRight; 

[self.view addGestureRecognizer:swipeRightRecognizer]; 
self.swipeRightRecognizer = (UISwipeGestureRecognizer *)recognizer; 
[recognizer release]; 

的感謝!

回答

0

您可以將滑動識別器添加到您想要滑動的視圖。或者,你可以這樣做:

swipeRightRecognizer.delegate = self; 
//... 


- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer 
     shouldReceiveTouch:(UITouch *)touch { 
    return (touch.view == myViewThatShouldReceiveSwipes); 
} 
+0

謝謝,但一切工作。你寫我可以將滑動識別器添加到我想要滑動的視圖中,怎麼樣? 謝謝 – Vins

+1

而不是'[self.view addGestureRecognizer:...]'只需使用[myViewThatShouldReceiveSwipes addGestureRecognizer:...]'。 – jtbandes