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

// 添加单击的手势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. Beaglebone Black – 连接 GY-91 MPU9250+BMP280 九轴传感器(2)

    这次用 SPI.BBB 有两套 SPI 接口可用,两套都是默认 disable,需要用 overlay 方式启用,即: echo BB-SPIDEV0 > /sys/devices/bone_c ...

  2. jquery validate 在ajax提交表单下的验证方法

    $(function() {  var method='${method }';  if(method == 'edit'){   url="${ctx}/commodity/typeReN ...

  3. USACO2011Brownie Slicing巧克力蛋糕切片

    Description     Bessie烘焙了一块巧克力蛋糕.这块蛋糕是由R*C(1 <= R,C <= 500)个小的巧克力蛋糕组成的. 第i行,第j列的蛋糕有N_ij(1 < ...

  4. int转string

    #include<iostream> #include<sstream> #include<string> using namespace std; int mai ...

  5. 基于zepto的一个日期区间选择插件

    功能:类似去哪选日期的那个日历,选第二个日期关闭日历,https://github.com/zhangchen2397/calendar在这个插件基础上改哒,这个只能选一个日期,我加了选两个日期的.并 ...

  6. “不支持一个STA线程上针对多个句柄的WaitAll。”的解决方案

    一.异常提示 不支持一个 STA 线程上针对多个句柄的 WaitAll. 出错界面如下图: 二.解决方法 先直接上解决方案吧.其实解决方法很简单如下面的代码直接把main函数的[STAThread]属 ...

  7. 使用ajax异步提交表单数据(史上最完整的版本)

    额 为啥用这个 不用form呢,因为这个效率高,而且在浏览器中运行程序的时候如果出现bug的话,页面不会显示显示错误信息,提高了用户的体验度. 那么,就来看看把,先给数据库表截个图哈 然后写项目被 我 ...

  8. 初学UML——用例图

    开始学习UML建模语言,从用例图入手.建模工具选择visio 用例图描述的是参与者所理解的系统功能,主要元素是用例和参与者,是帮助开发团队以一种可视化的方式理解系统的功能需求.这时处于项目初始,分析用 ...

  9. 解决Ubuntu 下 vi编辑器不能使用方向键和退格键问题

    转自:http://blog.csdn.net/sky101010ws/article/details/51012103 使用vi命令时,不能正常编辑文件,使用方向键时老是出现很多字母 这个问题主要是 ...

  10. iOS开发网络篇—网络编程基础

    iOS开发网络篇—网络编程基础 一.为什么要学习网络编程 1.简单说明 在移动互联网时代,移动应用的特征有: (1)几乎所有应用都需要用到网络,比如QQ.微博.网易新闻.优酷.百度地图 (2)只有通过 ...