问题
I am currently writting an ios5 app and call two functions (back) and (next) with buttons. I would like to call them with swipe gestures instead.
Would that be possible and how?
Thanks
回答1:
Use swipe gesture for both right direction (next button) and left direction (back button) For left direction:
UISwipeGestureRecognizer *swipeLeft =[[UISwipeGestureRecognizer alloc]
initWithTarget:self action:@selector(didSwipeLeft:)];
swipeLeft.direction=UISwipeGestureRecognizerDirectionLeft;
swipeLeft.numberOfTouchesRequired = 1;
[self.view addGestureRecognizer:swipeLeft];
[swipeLeft release];
For right direction:
UISwipeGestureRecognizer *swipeRight =[[UISwipeGestureRecognizer alloc]
initWithTarget:self action:@selector(didSwipeRight:)];
swipeRight .direction=UISwipeGestureRecognizerDirectionRight;
swipeRight .numberOfTouchesRequired = 1;
[self.view addGestureRecognizer:swipeRight ];
[swipeRight release];
You handle them with events:
-(void)didSwipeRight
{
//For right direction (next button)
}
-(void)didSwipeLeft
{
//For left direction (back button)
}
来源:https://stackoverflow.com/questions/10990060/ios5-swipe-gesture