iOS开发中的几个手势操作实例分享

2020-01-14 15:51:57于丽

  
    self.imageView.frame = CGRectMake(0, 0, 320, 200);  
    NSLog(@"%@",NSStringFromCGRect(self.imageView.frame));  
  
}  
  
#pragma mark  长按手势  
- (void)createLongGestureRecognizer{  
      
    _longGesture = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longGestureRecognizer:)];  
    _longGesture.numberOfTouchesRequired = 1;  
    _longGesture.minimumPressDuration = 1.0;  
    [self.imageView addGestureRecognizer:_longGesture];  
    [_longGesture release];  
      
}  
  
- (void)longGestureRecognizer:(UILongPressGestureRecognizer *)longGesture{  
  
    self.imageView.alpha = 0.5;  
    NSLog(@"%s",__FUNCTION__);  
  
}  
  
#pragma mark 平移拖拽手势  
- (void)createPanGestureRecognizer{  
      
    _panGesture = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGestureRecognizer:)];  
    [self.imageView addGestureRecognizer:_panGesture];  
    [_panGesture release];  
      
}  
  
- (void)panGestureRecognizer:(UIPanGestureRecognizer *)panGesture{  
      
    NSLog(@"%s",__FUNCTION__);  
   
    CGPoint txty = [panGesture translationInView:self.view];  
    self.imageView.transform = CGAffineTransformTranslate(self.imageView.transform, txty.x, txty.y);  
      
    [panGesture setTranslation:CGPointMake(0, 0) inView:self.view];  
      
}  
  
#pragma mark 旋转手势  
- (void)createRotationGestureRecognizer{  
      
      
    _rotateGesture = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationGestureRecognizer:)];  
    [self.imageView addGestureRecognizer:_rotateGesture];  
    [_rotateGesture release];