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) 旋转手 ...
随机推荐
- easyui 动态列
$.post('${createLink(action:"build Columns url ")}', params, function(data){ var columns = ...
- iOS常用第三方
名称 作用 说明 AFNetworking 基于HTTP协议联网 SDWebImage 图片缓存和异步加载 YYWebImage 图片缓存和异步加载 Ono XML解析 Rapture ...
- End Routine
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- java高薪之路__010_设计模式
设计模式只是一个在构建大型工程时,为了方便更改,添加,查询和管理的一种代码工具,没有必要单独为了设计模式而使用设计模式,使简单的事情复杂化. 总体来说设计模式分为三大类: 1. 创建型模式,共五种 - ...
- SurfaceOutput
下面着重分析一下surface shader中是如何使用BlinnPhong光照模型的,为以后写代码做铺垫.源文件取自Unity3D官网下载的builtin_shaders, 源文件名为Normal- ...
- i.BIO方式的SSL通道流程
前面已经讲解了BIO通道的整体流程,对于SSL的流程是插在通道中的,在BIO通道的初始化的时候,根据Connector配置的SSLEnabled属性进行SSL的逻辑. 主要集中的位置在JIOEndpo ...
- AWS 搭建 VPN 服务(PPTP & L2TP) 整理
只为记录和整理在AWS上假设VPN服务器帮助过我的资料,环境使用AWS EC2 东京区域, OS为ubuntu, PPTP和L2TP各自建立一个, 从speed test上看, 下载有2mbps左右, ...
- [maven] maven变量
Maven内置变量说明: $${project.basedir}或{basedir} 项目根目录,即包含pom.xml文件的目录 ${project.version}或${version}表示项目版本 ...
- TCP && UDP
TCP(Transmission Control Protocol,传输控制协议) 是面向连接的协议,也就是说,在收发数据前,必须和对方建立可靠的连接. TCP建立连接要进行3次握手,而断开连接要进行 ...
- java.util.logging.Logger 使用详解
概述: 第1部分 创建Logger对象 第2部分 日志级别 第3部分 Handler 第4部分 Formatter 第5部分 自定义 第6部分 Logger的层次关系 参考 第1部分 创建Logger ...