• IOS-开发中手势的处理


    手势识别
    一、1.点按
    UITapGestureRecognizer
    2.长按
    UILongPressGestureRecognizer
    if (UIGestureRecognizerStateBegan == recongnizer.state) {//如果自己的状态等于开始
    [recongnizer.view setTransform:CGAffineTransformMakeRotation(M_PI)];//就设置transform旋转属性为180;
    }else if(UIGestureRecognizerStateEnded == recongnizer.state){
    [recongnizer.view setTransform:CGAffineTransformIdentity];
    }
    3.拖动
    UIPanGestureRecognizer
    if (recongnizer.state == UIGestureRecognizerStateChanged) {
    CGPoint deltaPoint = [recongnizer translationInView:self.view];//判断在父视图平移的位置
    recongnizer.view.transform = CGAffineTransformMakeTranslation(deltaPoint.x, deltaPoint.y);
    }else if(recongnizer.state == UIGestureRecognizerStateEnded){
    recongnizer.view.transform = CGAffineTransformIdentity;
    }
    4.捏合
    UIPinchGestureRecognizer
    if (recongnizer.state == UIGestureRecognizerStateChanged) {
    recongnizer.view.transform = CGAffineTransformMakeScale(recongnizer.scale, recongnizer.scale);
    }else if(recongnizer.state == UIGestureRecognizerStateEnded){
    [UIView animateWithDuration:0.5 animations:^{
    recongnizer.view.transform = CGAffineTransformIdentity;
    }];
    }
    5.清扫
    UISwipeGestureRecognizer
    if (recongnizer.direction == UISwipeGestureRecognizerDirectionUp) {
    NSLog(@"向上");
    }else if (recongnizer.direction == UISwipeGestureRecognizerDirectionDown){
    NSLog(@"向下");
    }else if (recongnizer.direction == UISwipeGestureRecognizerDirectionLeft){
    NSLog(@"向左");
    }else if (recongnizer.direction == UISwipeGestureRecognizerDirectionRight){
    NSLog(@"向右");
    }
    6.旋转
    UIRotationGesturecognizer
    if (recongnizer.state == UIGestureRecognizerStateChanged) {
    recongnizer.view.transform = CGAffineTransformMakeRotation(M_PI);
    }
    二、综上所述:发现
    1>捏合,拖动,旋转,都需要判断状态改变和状态结束
    2>清扫需要设置方向,并且判断方向,默认是向右清扫
    3>长按需要判断状态开始,和状态结束
    4>其他可按需求判断

  • 相关阅读:
    实例代码讲解_Person
    推荐一个小工具:LINQ to JavaScript (jslinq)
    AJAX跨域问题解决一:使用web代理
    JQuery常用方法总结(2)
    对IEnumerable<T>,IDictionary<Tkey,TValue>,ICollection<T>,IList<T>的总结
    C#补零
    JQuery常用方法总结(1)
    单一模式(Singleton)的学习
    .net core 和 WPF 开发升讯威在线客服系统:调用百度翻译接口实现实时自动翻译
    在“宝塔”中部署升讯威在线客服系统教程来了,只需10分钟,确实方便!
  • 原文地址:https://www.cnblogs.com/yinqiang/p/3486802.html
Copyright © 2020-2023  润新知