iOS-响应上下左右滑动手势

 
 

-(void)viewDidLoad{

 

     UISwipeGestureRecognizer *recognizer; 

     recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];

     [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];

     [[self viewaddGestureRecognizer:recognizer];

     [recognizer release];

     recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];

     [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];

      [[self viewaddGestureRecognizer:recognizer];

      [recognizer release];

      recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];

      [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];

      [[self viewaddGestureRecognizer:recognizer];

      [recognizer release];

 

     UISwipeGestureRecognizer *recognizer;

     recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];

     [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];

     [[self viewaddGestureRecognizer:recognizer];

      [recognizer release];

}

-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{

 

        if(recognizer.direction==UISwipeGestureRecognizerDirectionDown) {

               NSLog(@"swipe down");

               //执行程序

        }

        if(recognizer.direction==UISwipeGestureRecognizerDirectionUp) {

               NSLog(@"swipe up");

               //执行程序

         }


 

         if(recognizer.direction==UISwipeGestureRecognizerDirectionLeft) {

                NSLog(@"swipe left");

                //执行程序

           }


 

          if(recognizer.direction==UISwipeGestureRecognizerDirectionRight) {

               NSLog(@"swipe right");

                //执行程序

           }


}

posted @ 2012-08-03 16:55  奔放小青年  阅读(5278)  评论(0编辑  收藏  举报