手势识别是具有互斥的原则的,比如单击和双击,如果它识别出一种手势,其后的手势将不被识别

// 添加单击的手势UITapGestureRecognize

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] init];

[tapGestureRecognizer addTarget:self action:@selector(tapGestureAction:)]; // 添加点击手势的方法

[self.view addGestureRecognizer:tapGestureRecognizer]; // 添加到当前的View上

// 添加双击的手势UITapGestureRecognize

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] init];

tapGestureRecognizer.numberOfTapsRequired = 2; // 设置单击几次才触发方法

[tapGestureRecognizer addTarget:self action:@selector(tapGestureAction:)]; // 添加点击手势的方法

[self.view addGestureRecognizer:tapGestureRecognizer]; // 添加到当前的View上

添加长按的手势UILongPressGestureRecognizer

注意:会调用两次方法,开始长按调用一次  松开后再调用一次  当长按并且滑动的时候,会多次调用长按的方法

UILongPressGestureRecognizer *pressLongGestureRecognizer = [[UILongPressGestureRecognizeralloc] init];

[pressLongGestureRecognizer addTarget:self action:@selector(pressLongGestureAction:)]; // 给长按手势添加方法

[self.view addGestureRecognizer:pressLongGestureRecognizer]; // 添加到当前的View上

添加捏合的手势UIPinchGestureRecognizer

注意:捏合手势不是捏合一次调用一次方法,而是在捏合的过程中不停的调用方法

UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] init];

[pinchGestureRecognizer addTarget:self action:@selector(pinchGestureAction:)]; // 添加捏合手势的方法

[self.view addGestureRecognizer:pinchGestureRecognizer]; // 添加到当前的View上

添加旋转的手势UIRotationGestureRecognizer

注意:旋转手势是两指同时进行旋转

UIRotationGestureRecognizer *rotationGestureRecognizer = [[UIRotationGestureRecognizeralloc] init];

[rotationGestureRecognizer addTarget:self action:@selector(rotationGestureAction:)]; // 给旋转手势添加方法

[self.view addGestureRecognizer:rotationGestureRecognizer]; // 添加到当前的View上

添加滑动的手势(轻扫手势) UISwipeGestureRecognizer

注意: 快速移动,是用于监测滑动的方向的

UISwipeGestureRecognizer *swipGestureRecognizer = [[UISwipeGestureRecognizer alloc] init];

swipGestureRecognizer.direction = UISwipeGestureRecognizerDirectionUp; // 添加手势的方法

// 以下是设置滑动的方向

// typedef NS_OPTIONS(NSUInteger, UISwipeGestureRecognizerDirection) {

//    UISwipeGestureRecognizerDirectionRight = 1 << 0, // 从左向右滑动

//    UISwipeGestureRecognizerDirectionLeft  = 1 << 1, // 从右向左滑动

//    UISwipeGestureRecognizerDirectionUp    = 1 << 2, // 从下向上滑动

//    UISwipeGestureRecognizerDirectionDown  = 1 << 3  // 从上向下滑动

// };

[swipGestureRecognizer addTarget:self action:@selector(swipGestureAction:)]; // 给滑动手势添加方法

[self.view addGestureRecognizer:swipGestureRecognizer]; // 添加到当前的View上

添加拖移手势(平移手势) UIPanGestureRecognizer

注意:慢速移动,是用于监测偏移的量的

UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] init];

[panGestureRecognizer addTarget:self action:@selector(panGestureAction:)]; // 添加托移收拾的方法

[self.view addGestureRecognizer:panGestureRecognizer]; // 添加到当前的View

[panGestureRecognizer release], panGestureRecognizer = nil; // 释放内存

 

#pragma mark - 实现单击手势的方法

- (void)tapGestureAction:(UITapGestureRecognizer *) sender {

NSLog(@"您  轻拍   了屏幕");

}

#pragma mark - 实现长按手势的方法

- (void)pressLongGestureAction:(UILongPressGestureRecognizer *) sender {

NSLog(@"您   长按   了屏幕");

}

#pragma mark - 实现了捏合手势的方法

- (void)pinchGestureAction:(UIPinchGestureRecognizer *) sender {

NSLog(@"您   捏合   了屏幕");

}

#pragma mark - 实现旋转手势的方法

- (void)rotationGestureAction:(UIRotationGestureRecognizer *) sender {

NSLog(@"您使用了   旋转   手势");

}

#pragma mark - 实现滑动手势的方法

- (void)swipGestureAction:(UISwipeGestureRecognizer *) sender {

NSLog(@"您   滑动    了屏幕");

}

#pragma mark - 实现了托移手势的方法

- (void)panGestureAction:(UIPanGestureRecognizer *) sender {

NSLog(@"您   托移   了。。。。");

}

晃动手势

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions

{

application.applicationSupportsShakeToEdit = YES;

return YES;

}

-(BOOL)canBecomeFirstResponder {

return YES;

}

-(void)viewDidAppear:(BOOL)animated {

[super viewDidAppear:animated];

[self becomeFirstResponder];

}

- (void)viewWillDisappear:(BOOL)animated {

[self resignFirstResponder];

[super viewWillDisappear:animated];

}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event

{

if (motion == UIEventSubtypeMotionShake) {

NSLog(@"检测到晃动");

}

}

IOS--手势控制的使用的更多相关文章

  1. ios手势

    iOS 手势操作:拖动.捏合.旋转.点按.长按.轻扫.自定义 大 中 小   1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. i ...

  2. iOS视图控制对象生命周期

    iOS视图控制对象生命周期-init.viewDidLoad.viewWillAppear.viewDidAppear.viewWillDisappear.viewDidDisappear的区别及用途 ...

  3. Swift实战-豆瓣电台(九)简单手势控制暂停播放(全文完)

    Swift实战-豆瓣电台(九)简单手势控制暂停播放 全屏清晰观看地址:http://www.tudou.com/programs/view/tANnovvxR8U/ 这节我们主要讲UITapGestu ...

  4. iOS手势学习UIGestureRecognizer & cocos2d 手势推荐

    iOS手势学习UIGestureRecognizer & cocos2d 手势推荐 手势识别类型: UILongPressGestureRecognizer  // 长按UIPanGestur ...

  5. Unity3D中使用Leap Motion进行手势控制

    Leap Motion作为一款手势识别设备,相比于Kniect,长处在于准确度. 在我的毕业设计<场景漫游器>的开发中.Leap Motion的手势控制作为重要的一个环节.以此,谈谈开发中 ...

  6. IOS 视图控制对象生命周期-init、viewDidLoad、viewWillAppear、viewDidAppear、viewWillDisappear等的区别及用途

    iOS视图控制对象生命周期-init.viewDidLoad.viewWillAppear.viewDidAppear.viewWillDisappear.viewDidDisappear的区别及用途 ...

  7. Visual Studio跨平台开发实战(2) - Xamarin.iOS基本控制项介绍

    原文 Visual Studio跨平台开发实战(2) - Xamarin.iOS基本控制项介绍 前言 在上一篇文章中, 我们介绍了Xamarin 以及简单的HelloWorld范例, 这次我们针对iO ...

  8. iOS手势处理

    iOS手势处理 iOS手势有着如下几种: UITapGestureRecognizer UIPinchGestureRecognizer UIRotationGestureRecognizer UIS ...

  9. MIT 黑科技:通过脑电波和手势控制机器人

    简评:麻省理工黑科技,虽然现在能实现的操作还很简单,但前景(想象空间)非常巨大. 通常,控制机器人并不容易,常规手段就是编程.但是地球上从来不缺天马行空的科学家,今日 MIT 的计算机科学与人工智能实 ...

  10. iOS 手势识别器概述

    手势识别器 iOS 手势识别器(UIGestureRecognizer) 点击手势(UITapGestureRecognizer) 滑动手势(UISwipeGestureRecognizer) 旋转手 ...

随机推荐

  1. [问题2014A08] 解答

    [问题2014A08] 解答 由假设知 \(f(A)=\mathrm{tr}(AA')\), 因此 \[f(PAP^{-1})=\mathrm{tr}(PAP^{-1}(P')^{-1}A'P')=\ ...

  2. jQuery验证元素是否为空的两种常用方法

    这篇文章主要介绍了jQuery验证元素是否为空的两种常用方法,实例分析了两种常用的判断为空技巧,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了jQuery验证元素是否为空的两种常用方法.分享给 ...

  3. 判断ie?

    <!DOCTYPE html> <html lang="en"> <head> <script type="text/javas ...

  4. Android项目开发遇到的问题(64K的错误)的解决之路,从入坑到出坑

    自己一个android项目,一直以来进展还算顺利,没有遇到什么严重性的问题,今天准备给同事手机上安装一下玩玩,谁知丢人丢大,无法build apk!报错!my god,我开发没问题啊,我手机连上usb ...

  5. C#程序设计---->计算圆面积windows程序

    值得说的就是添加一个回车事件, http://blog.csdn.net/nanwang314/article/details/6176604 private void textBox1_KeyDow ...

  6. Java面向对象三大特点之继承

    概念: 继承就是子类继承父类的特征和行为,使得子类对象(实例)具有父类的实例域和方法,或子类从父类继承方法,使得子类具有父类相同的行为. 生活中的继承: 兔子和羊属于食草动物类,狮子和豹属于食肉动物类 ...

  7. TCP/IP协议学习(四) 协议概述

    生活中有舒适区,借口成为懒惰的护身符,学习也有舒适区,逃避便是阻止进步的最大障碍. 经过半年多嵌入式方面的工作和学习,我提高了很多,但同时我也对自己所面临的问题逐渐清晰: 1. 偏于实践,理论基础不牢 ...

  8. Failed to execute goal org.codehaus.mojo:rpm-maven-plugin:2.1.1:rpm (default) on project **

    maven编译项目时报错:Failed to execute goal org.codehaus.mojo:rpm-maven-plugin:2.1.1:rpm (default) on projec ...

  9. php短路与 短路或

    关于php短路的问题特性,三种写法的区别 $a = 1;$b=0;第一种: $a && $b = 'cccccccc';第二种 $a || $b = 'cccccccc';第三种 if ...

  10. java jar包解析:打包文件,引入文件

    java jar包解析:打包文件,引入文件 cmd下: jar命令:package包打包 javac命令:普通类文件打包 Hello.java: package org.lxh.demo; publi ...