我有一些麻煩來處理iPhone
刷卡,我在界面中創建一個UISwipeGestureRecognizer
VAR:輕掃手勢iphone
UISwipeGestureRecognizer *swipeRecognizer;
,並在我的控制器:viewDidLoad
方法
- (void)viewDidLoad
{
[super viewDidLoad];
// Horizontal swipe
swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(swipeMethod:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
[self addGestureRecognizer:swipeRecognizer];
}
而我的方法處理滑動是:
-(void)swipeMethod: (UISwipeGestureRecognizer *) sender
{
NSLog(@"Swipe!");
}
當我運行我的代碼和d o刷卡什麼都沒有?我應該得到:刷卡!
謝謝。
不要將它添加到self,要麼使用self.view(假設self是viewcontroller),要麼使用子視圖將手勢識別器置於其上。您可以在放置識別器之前放置一個斷點並查看它是否正確添加。看到我的答案左和右滑動檢測:http://stackoverflow.com/a/16810160/936957 – 2013-05-29 09:32:21