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) 旋转手 ...
随机推荐
- Java-简陋的图书管理
本文代码为原创一个简陋的管理系统,只做功能的测试.并没有去完善所有应有的功能,只做了输入输出查找.仅供参考! 菜单部分: import java.util.Scanner; public class ...
- CSS设置透明的两种方式
1..demo{ background-color:transparent; } 2..demo{ background-color:rgba(0,0,0,0.5); //最后一个参数是用来设置透明度 ...
- OpenCV图像处理中常用函数汇总(2)
// 霍夫线变换 hough vector<Vec2f> lines;//定义一个矢量结构lines用于存放得到的线段矢量集合 HoughLines(dstImage,lines,,CV_ ...
- python核心编程第六章练习6-14
随机数.设计一个“石头.剪子.布”游戏,有时又叫“Rochambeau”,你小时候可能玩过,下面是规则.你和你的对手,在同一时间做出特定的手势,必须是下面一种:石头.剪子.布.胜利者从下面的规则产生, ...
- sentinel搭建redis集群经验总结
一.protected-mode默认情况下,redis node和sentinel的protected-mode都是yes,在搭建集群时,若想从远程连接redis集群,需要将redis node和se ...
- logistic回归模型
一.模型简介 线性回归默认因变量为连续变量,而实际分析中,有时候会遇到因变量为分类变量的情况,例如阴性阳性.性别.血型等.此时如果还使用前面介绍的线性回归模型进行拟合的话,会出现问题,以二分类变量为例 ...
- zju 1002
// zju 1002 // #include "stdafx.h" #include <string> #include <iostream> using ...
- 解决Selenium与firefox浏览器版本不兼容问题
因为在用java打开firefox浏览器的时候报错 org.openqa.selenium.firefox.NotConnectedException: Unable to connect to ho ...
- DIV设置overflow无效的原因
因为项目需求需要在一个div中添加多个checked 添加的时候使用了 <label><input type="checkbox" value="123 ...
- c#连接各种数据库
1.C#连接连接Access程序代码: ------------------------------------------------------------------------------- ...