2012-06-12 102 views
0

我目前正在写一个ios5应用程序并使用按钮调用两个函数(后退)和(下一个)。 我想用滑动手势代替他们。Ios5轻扫手势

会是可能的和如何?

感谢

回答

4

使用滑动手势了右方向(下一个按钮)和左方向(后退键) 左方向:

UISwipeGestureRecognizer *swipeLeft =[[UISwipeGestureRecognizer alloc] 
    initWithTarget:self action:@selector(didSwipeLeft:)]; 
swipeLeft.direction=UISwipeGestureRecognizerDirectionLeft; 
swipeLeft.numberOfTouchesRequired = 1; 
[self.view addGestureRecognizer:swipeLeft]; 
[swipeLeft release]; 

对于正确的方向:

UISwipeGestureRecognizer *swipeRight =[[UISwipeGestureRecognizer alloc] 
    initWithTarget:self action:@selector(didSwipeRight:)]; 
swipeRight .direction=UISwipeGestureRecognizerDirectionRight; 
swipeRight .numberOfTouchesRequired = 1; 
[self.view addGestureRecognizer:swipeRight ]; 
[swipeRight release]; 

你用事件处理它们:

-(void)didSwipeRight 
{ 
    //For right direction (next button) 
} 

    -(void)didSwipeLeft 
{ 
    //For left direction (back button) 
} 
+0

谢谢你的代码。请您详细说明您的答案,并告诉我如何将其与“页面控制”集成?如果我需要连接它与故事板。我已upvoted你的答案:) – user1949873