首页 > 代码库 > UIView上的滑动手势及动作

UIView上的滑动手势及动作

 
  1. ///////////注flowView为UIView//////////  
  2.  //添加滑动手势事件  
  3.     UIPanGestureRecognizer *gestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:flowView action:@selector(handleGesture:)];  
  4.     [flowView addGestureRecognizer:gestureRecognizer];  
  5.       
  6.     //添加点击手势事件  
  7.     flowView.userInteractionEnabled = YES;  
  8.     UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:flowView action:@selector(goBigImageView)];  
  9.     [flowView addGestureRecognizer:tap];  

 

 
  1. //滑动手势(里面有手势的不同状态,根据需要进行灵活运用)  
  2. - (void)handleGesture:(UIPanGestureRecognizer *)recognizer {  
  3.     //UITapGestureRecognizer  
  4.    if (recognizer.state == UIGestureRecognizerStateChanged){  
  5.        NSLog(@"UIGestureRecognizerStateChanged");  
  6.    }else if(recognizer.state == UIGestureRecognizerStateEnded){  
  7.        NSLog(@"UIGestureRecognizerStateEnded");  
  8.    }else if(recognizer.state == UIGestureRecognizerStateBegan){  
  9.        NSLog(@"UIGestureRecognizerStateBegan");  
  10.    }else if(recognizer.state == UIGestureRecognizerStateCancelled){  
  11.        NSLog(@"UIGestureRecognizerStateCancelled");  
  12.    }else if(recognizer.state == UIGestureRecognizerStateFailed){  
  13.        NSLog(@"UIGestureRecognizerStateFailed");  
  14.    }else if(recognizer.state == UIGestureRecognizerStatePossible){  
  15.        NSLog(@"UIGestureRecognizerStatePossible");  
  16.    }else if(recognizer.state == UIGestureRecognizerStateRecognized){  
  17.        NSLog(@"UIGestureRecognizerStateRecognized");  
  18.    }  
  19.   
  20. }