IOS--手势控制的使用
手势识别是具有互斥的原则的,比如单击和双击,如果它识别出一种手势,其后的手势将不被识别
// 添加单击的手势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--手势控制的使用的更多相关文章
- ios手势
iOS 手势操作:拖动.捏合.旋转.点按.长按.轻扫.自定义 大 中 小 1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. i ...
- iOS视图控制对象生命周期
iOS视图控制对象生命周期-init.viewDidLoad.viewWillAppear.viewDidAppear.viewWillDisappear.viewDidDisappear的区别及用途 ...
- Swift实战-豆瓣电台(九)简单手势控制暂停播放(全文完)
Swift实战-豆瓣电台(九)简单手势控制暂停播放 全屏清晰观看地址:http://www.tudou.com/programs/view/tANnovvxR8U/ 这节我们主要讲UITapGestu ...
- iOS手势学习UIGestureRecognizer & cocos2d 手势推荐
iOS手势学习UIGestureRecognizer & cocos2d 手势推荐 手势识别类型: UILongPressGestureRecognizer // 长按UIPanGestur ...
- Unity3D中使用Leap Motion进行手势控制
Leap Motion作为一款手势识别设备,相比于Kniect,长处在于准确度. 在我的毕业设计<场景漫游器>的开发中.Leap Motion的手势控制作为重要的一个环节.以此,谈谈开发中 ...
- IOS 视图控制对象生命周期-init、viewDidLoad、viewWillAppear、viewDidAppear、viewWillDisappear等的区别及用途
iOS视图控制对象生命周期-init.viewDidLoad.viewWillAppear.viewDidAppear.viewWillDisappear.viewDidDisappear的区别及用途 ...
- Visual Studio跨平台开发实战(2) - Xamarin.iOS基本控制项介绍
原文 Visual Studio跨平台开发实战(2) - Xamarin.iOS基本控制项介绍 前言 在上一篇文章中, 我们介绍了Xamarin 以及简单的HelloWorld范例, 这次我们针对iO ...
- iOS手势处理
iOS手势处理 iOS手势有着如下几种: UITapGestureRecognizer UIPinchGestureRecognizer UIRotationGestureRecognizer UIS ...
- MIT 黑科技:通过脑电波和手势控制机器人
简评:麻省理工黑科技,虽然现在能实现的操作还很简单,但前景(想象空间)非常巨大. 通常,控制机器人并不容易,常规手段就是编程.但是地球上从来不缺天马行空的科学家,今日 MIT 的计算机科学与人工智能实 ...
- iOS 手势识别器概述
手势识别器 iOS 手势识别器(UIGestureRecognizer) 点击手势(UITapGestureRecognizer) 滑动手势(UISwipeGestureRecognizer) 旋转手 ...
随机推荐
- 类似\u4e0b\u6ce8\u903e\u65f6解码
HttpUtility.UrlDecode("\u4e0b\u6ce8\u903e\u65f6"); HttpUtility.UrlDecode("\\u5c1a\\u6 ...
- java使用split切割字符串的时候,注意转义字符
今天在做项目的时候发现一个奇怪的问题 File file = new File("d:\\a.txt"); BufferedReader br = new BufferedRead ...
- JavaScript严格模式详解
转载自阮一峰的博客 Javascript 严格模式详解 作者: 阮一峰 一.概述 除了正常运行模式,ECMAscript 5添加了第二种运行模式:"严格模式"(strict m ...
- Java线程中yield与join方法的区别
长期以来,多线程问题颇为受到面试官的青睐.虽然我个人认为我们当中很少有人能真正获得机会开发复杂的多线程应用(在过去的七年中,我得到了一个机会),但是理解多线程对增加你的信心很有用.之前,我讨论了一个w ...
- Python之路 day2 初识字典
#Author:ersa ''' key-value 键值对 字典是无序的,不需要下标,有key 字典的查找.修改.添加.判断.删除 ''' info = { 'stu1101': "Ten ...
- link和@import的区别
link属于XHTML标签,而@import完全是css提供的一种方式:标签和css样式的区别就不说了,他们起到的作用区别不大,一般建议用link因为简单,@import会对页面载入有影响,影响性能l ...
- Xcode集成开发环境的安装
Xcode是苹果官方提供的iOS开发环境,安装方式如下: 安装过程需要登录AppleID账号,如果你没有苹果账号,可以免费注册一个.根据提示就能完成Xcode安装.
- 51nod 1183 编辑距离(dp)
题目链接:51nod 1183 编辑距离 #include<cstdio> #include<cstring> #include<algorithm> using ...
- Effective Java阅读笔记——引言
“我很希望10年前就拥有这本书.可能有人认为我不需要任何Java方面的书籍,但是我需要这本书.” ——Java之父 James Gosling 在图书馆找到这本java著作时,首先看到了这句话. ...
- iOS基础篇(十五)——UIScrollView的基本用法
滚动视图(UIScrollView)通常用于显示内容尺寸大于屏幕尺寸的视图. 一.基本属性 1.CGSize contentSize :设置UIScrollView的滚动范围 2.CGPoint co ...