zoukankan      html  css  js  c++  java
  • 0128——手势Gesture

    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;

    }

  • 相关阅读:
    Git撤销commit消息保留修改
    switchysharp设置
    Windows10下的docker安装与入门 (三) 创建自己的docker镜像并且在容器中运行它
    Windows10下的docker安装与入门 (二)使用docker引擎在容器中运行镜像
    Windows10下的docker安装与入门 (一)使用docker toolbox安装docker
    semver(Semantic Versioning)
    conda install mingw libpython
    下载 安装MYsql 服务器
    .NET(c#) 移动APP开发平台
    .NET(c#) 移动APP开发平台
  • 原文地址:https://www.cnblogs.com/damonWq/p/5168608.html
Copyright © 2011-2022 走看看