六种手势识别,你用了哪些?

//1,轻击手势(TapGestureRecognizer)

//新建tap手势
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
//设置点击次数和点击手指数
tapGesture.numberOfTapsRequired = 1; //点击次数
tapGesture.numberOfTouchesRequired = 1; //点击手指数
[self.view addGestureRecognizer:tapGesture];

//轻击手势触发方法
-(void)tapGesture:(id)sender
{
    //轻击后要做的事情
}
//2,长按手势(LongPressGestureRecognizer)

//添加长摁手势
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGesture:)];
//设置长按时间
longPressGesture.minimumPressDuration = 0.5; //(2秒)
[self.view addGestureRecognizer:longPressGesture];

//常摁手势触发方法
-(void)longPressGesture:(id)sender
{
    UILongPressGestureRecognizer *longPress = sender;
    if (longPress.state == UIGestureRecognizerStateBegan)
    {
        UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"长按触发" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles: nil];
        [alter show];
    }
}
//3,轻扫手势(SwipeGestureRecognizer)

//添加轻扫手势
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
//设置轻扫的方向
swipeGesture.direction = UISwipeGestureRecognizerDirectionRight; //默认向右
[self.view addGestureRecognizer:swipeGesture];

//添加轻扫手势
UISwipeGestureRecognizer *swipeGestureLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
//设置轻扫的方向
swipeGestureLeft.direction = UISwipeGestureRecognizerDirectionLeft; //默认向右
[self.view addGestureRecognizer:swipeGestureLeft];

//轻扫手势触发方法
-(void)swipeGesture:(id)sender
{
    UISwipeGestureRecognizer *swipe = sender;
    if (swipe.direction == UISwipeGestureRecognizerDirectionLeft)
    {
        //向左轻扫做的事情
    }
    if (swipe.direction == UISwipeGestureRecognizerDirectionRight)
    {
        //向右轻扫做的事情
    }
}
//4,捏合手势(PinchGestureRecognizer)

//添加捏合手势
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGesture:)];
[self.view addGestureRecognizer:pinchGesture];

////捏合手势触发方法
-(void) pinchGesture:(id)sender
{
    UIPinchGestureRecognizer *gesture = sender;

    //手势改变时
    if (gesture.state == UIGestureRecognizerStateChanged)
    {
        //捏合手势中scale属性记录的缩放比例
        _imageView.transform = CGAffineTransformMakeScale(gesture.scale, gesture.scale);
    }

    //结束后恢复
    if(gesture.state==UIGestureRecognizerStateEnded)
    {
        [UIView animateWithDuration:0.5 animations:^{
            _imageView.transform = CGAffineTransformIdentity;//取消一切形变
        }];
    }
}
//5,拖动手势(PanGestureRecognizer)

//添加拖动手势
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGesture:)];
[self.view addGestureRecognizer:panGesture];

//拖动手势
-(void) panGesture:(id)sender
{
    UIPanGestureRecognizer *panGesture = sender;

    CGPoint movePoint = [panGesture translationInView:self.view];

    //做你想做的事儿
}
//6,旋转手势(RotationGestureRecognizer)

//添加旋转手势
UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGesture:)];
[self.view addGestureRecognizer:rotationGesture];

//旋转手势
-(void)rotationGesture:(id)sender
{

    UIRotationGestureRecognizer *gesture = sender;

    if (gesture.state==UIGestureRecognizerStateChanged)
    {
        _imageView.transform=CGAffineTransformMakeRotation(gesture.rotation);
    }

    if(gesture.state==UIGestureRecognizerStateEnded)
    {

        [UIView animateWithDuration:1 animations:^{
            _imageView.transform=CGAffineTransformIdentity;//取消形变
        }];
    }

}
时间: 2024-08-27 23:11:36

六种手势识别,你用了哪些?的相关文章

iOS开发中六种手势识别

iOS开发中手势识别有六种: 轻击手势(TapGestureRecognizer), 轻扫手势 (SwipeGestureRecognizer), 长按手势(LongPressGestureRecognizer), 拖动手势(PanGestureRecognizer), 捏合手势(PinchGestureRecognizer), 旋转手势(RotationGestureRecognizer), 1,轻击手势(TapGestureRecognizer) UITapGestureRecognizer

iOS开发系列--触摸事件、手势识别、摇晃事件、耳机线控

-- iOS事件全面解析 概览 iPhone的成功很大一部分得益于它多点触摸的强大功能,乔布斯让人们认识到手机其实是可以不用按键和手写笔直接操作的,这不愧为一项伟大的设计.今天我们就针对iOS的触摸事件(手势操作).运动事件.远程控制事件等展开学习: iOS事件简介 触摸事件 手势识别 运动事件 远程控制事件 iOS事件 在iOS中事件分为三类: 触摸事件:通过触摸.手势进行触发(例如手指点击.缩放) 运动事件:通过加速器进行触发(例如手机晃动) 远程控制事件:通过其他远程设备触发(例如耳机控制

转发:iOS开发系列--触摸事件、手势识别、摇晃事件、耳机线控

-- iOS事件全面解析 转载来自崔江涛(KenshinCui) 链接:http://www.cnblogs.com/kenshincui/p/3950646.html 概览 iPhone的成功很大一部分得益于它多点触摸的强大功能,乔布斯让人们认识到手机其实是可以不用按键和手写笔直接操作的,这不愧为一项伟大的设计.今天我们就针对iOS的触摸事件(手势操作).运动事件.远程控制事件等展开学习: iOS事件简介 触摸事件 手势识别 运动事件 远程控制事件 iOS事件 在iOS中事件分为三类: 触摸事

iOS开发之手势识别

感觉有必要把iOS开发中的手势识别做一个小小的总结.在上一篇iOS开发之自定义表情键盘(组件封装与自动布局)博客中用到了一个轻击手势,就是在轻击TextView时从表情键盘回到系统键盘,在TextView中的手是用storyboard添加的.下面会先给出如何用storyboard给相应的控件添加手势,然后在用纯代码的方式给我们的控件添加手势,手势的用法比较简单.和button的用法类似,也是目标动作回调,话不多说,切入今天的正题.总共有六种手势识别:轻击手势(TapGestureRecogniz

[转载]iOS开发之手势识别

感觉有必要把iOS开发中的手势识别做一个小小的总结.在上一篇iOS开发之自定义表情键盘(组件封装与自动布局)博客中用到了一个轻击手势,就是在轻击TextView时从表情键盘回到系统键盘,在TextView中的手是用storyboard添加的.下面会先给出如何用storyboard给相应的控件添加手势,然后在用纯代码的方式给我们的控件添加手势,手势的用法比较简单.和button的用法类似,也是目标动作回调,话不多说,切入今天的正题.总共有六种手势识别:轻击手势(TapGestureRecogniz

IOS 使用手势识别

六种手势识别(继承于UIGestureRecongnizer基类): UITapGestureRecongnizer--检测view上的单击操作 UIPinchGestureRecongnizer--检测view上两个手指的缩放操作 UIPanGestureRecongnizer--检测view的拖拽操作 UISwipeGestureRecongnizer--检测view的轻划操作 UIRotationGestureRecongnizer--检测view的旋转操作 UILongPressGest

iOS手势操作,拖动,轻击,捏合,旋转,长按,自定义(http://www.cnblogs.com/huangjianwu/p/4675648.html)

1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. iOS 系统在 3.2 以后,他提供了一些常用的手势(UIGestureRecognizer 的子类),开发者可以直接使用他们进行手势操作. UIPanGestureRecognizer(拖动) UIPinchGestureRecognizer(捏合) UIRotationGestureRecognizer(旋转) UITapGestureRecognizer(点按) UILo

iOS--手势之谜

原文转至: http://www.cnblogs.com/huangjianwu/p/4675648.html iOS在手机APP的手势操作中包含了:拖动.捏合.旋转.点按.长按.轻扫.自定义等等,详情如下: 1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. iOS 系统在 3.2 以后,他提供了一些常用的手势(UIGestureRecognizer 的子类),开发者可以直接使用他们进行手势操作. UIPanGestureRe

手势(转)

代码改变世界 Posts - 69, Articles - 0, Comments - 834 Cnblogs Dashboard Logout HOME CONTACT GALLERY RSS Kenshin Cui's BlogCODING 完美世界... iOS开发系列--触摸事件.手势识别.摇晃事件.耳机线控 2014-09-02 06:33 by KenshinCui, 9064 阅读, 19 评论, 收藏,  编辑 -- iOS事件全面解析 概览 iPhone的成功很大一部分得益于它