博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UIGestureRecognizer手势
阅读量:4570 次
发布时间:2019-06-08

本文共 2467 字,大约阅读时间需要 8 分钟。

UIGestureRecognizer:

1.locationinView 获取手势在某个视图里面的坐标位置

2.delegate监听手势的行为

3.state状态

  开始:UIGestureRecognizerStateBegan  手势达到要求

  识别:UIGestureRecognizerStateRecognized  手势识别的最后一刻

  改变:UIGestureRecognizerStateChanged  手势过程当中

  结束:UIGestureRecognizerStateEnded  手势结束

  取消:UIGestureRecognizerStateCancelled

  失败:UIGestureRecognizerStateFailed

1.单击

UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(handleSingleFingerEvent:)];

singleFingerOne.numberOfTouchesRequired = 1; 手指数

singleFingerOne.numberOfTapsRequired = 1; tap次数

2.长按

UILongPressGestureRecognizer *longpressGesutre=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongpressGesture:)];  

longpressGesutre.minimumPressDuration=1;  最少长按时间

longpressGesutre.allowableMovement=15; 最大15像素的运动是手势识别所允许的  

3.滑动

UISwipeGestureRecognizer *swipeGesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeGesture:)];  

swipeGesture.direction=UISwipeGestureRecognizerDirectionLeft; 不设置是右  多个方向用|或

4.捏

UIPinchGestureRecognizer *pinchGesture=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(PinchGesture:)];  

-(void) pinchGesture:(id)sender
{
     UIPinchGestureRecognizer *gesture = sender;     
    //手势改变时
    if (gesture.state == UIGestureRecognizerStateChanged)
{
        //捏合手势中scale属性记录的缩放比例
        _imageView.transform = CGAffineTransformScale(_imageView.transform,gesture.scale, gesture.scale);
    }    
    //结束后恢复
    if(gesture.state==UIGestureRecognizerStateEnded)
{
        [UIView animateWithDuration:0.5 animations:^{
            _imageView.transform = CGAffineTransformIdentity;//取消一切形变
        }];
    }
}
5.旋转
UIRotateGestureRecognizer *rotateGesture=[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationGesture:)]; 
-(void)rotationGesture:(id)sender{
    
  UIRotateGestureRecognizer *gesture = sender;      
  if (gesture.state==UIGestureRecognizerStateChanged){
        
    _imageView.transform=CGAffineTransform=Rotation(_imageView.transform,gesture.rotation);    
  }       
  if(gesture.state==UIGestureRecognizerStateEnded){
        
    [UIView animateWithDuration:1 animations:^{
            
      _imageView.transform=CGAffineTransformIdentity;//取消形变   
      }];   
   }   
 }

 

6.多手势

ios开发中,默认是在同一时间只能有一个手势被执行,要实现多个手势同时进行,须实现UIGestureRecognizerDelegate,并重写函数

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{

return YES;

}

转载于:https://www.cnblogs.com/huoran1120/p/5165479.html

你可能感兴趣的文章
Android 采用HttpClient提交数据到服务器
查看>>
EL表达式概述
查看>>
word中批量修改图片大小
查看>>
Ext4 中 日期和时间的控件
查看>>
最长子序列问题
查看>>
python中一些有用的函数------持续更新中
查看>>
第三次作业—张淑华
查看>>
python 实现字符串的切片功能
查看>>
Centos 文件权限修改
查看>>
使用Amazon Simple Queues Service (SQS)实现与AutoCAD远程交互
查看>>
oracle 游标
查看>>
滚动条滚动到最底部的方法总结
查看>>
想不劳而获的人太多了,而我就是其中一个
查看>>
hexo改造
查看>>
Python模块NumPy中的tile(A,rep) 函数
查看>>
JS实现打开本地文件或文件夹 ActiveXObject
查看>>
python中split函数的使用
查看>>
优化 SQL SELECT 语句性能
查看>>
Spring3 MVC 类型转换
查看>>
9260与SAM-BA连接(转)
查看>>