使用iOS手势UIGestureRecognizer
1、拍击UITapGestureRecognizer (任意次数的拍击)
2、向里或向外捏UIPinchGestureRecognizer (用于缩放)
3、摇动或者拖拽UIPanGestureRecognizer
4、擦碰UISwipeGestureRecognizer (以任意方向)
5、旋转UIRotationGestureRecognizer (手指朝相反方向移动)
6、长按UILongPressGestureRecognizer
对 于不同类型的手势识别器,具有不同的配置属性。比如UITapGestureRecognizer,可以配置拍击次数。界面接收到手势之后,可以发送一个 消息,用于处理响应手势动作后的任务。当然,不同的手势识别器,发送的消息方法也会有所不同。下面列举几个具体示例代码:
1、一个手指,拍击两次手势
// 创建一个手势识别器
UITapGestureRecognizer *oneFingerTwoTaps =
[[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerTwoTaps)] autorelease];
// Set required taps and number of touches
[oneFingerTwoTaps setNumberOfTapsRequired:2];
[oneFingerTwoTaps setNumberOfTouchesRequired:1];
// Add the gesture to the view
[[self view] addGestureRecognizer:oneFingerTwoTaps];
消息方法oneFingerTwoTaps
- (void)oneFingerTwoTaps
{
NSLog(@"Action: One finger, two taps");
}
2、两个手指,拍击两次手势
UITapGestureRecognizer *twoFingersTwoTaps =
[[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingersTwoTaps)] autorelease];
[twoFingersTwoTaps setNumberOfTapsRequired:2];
[twoFingersTwoTaps setNumberOfTouchesRequired:2];
[[self view] addGestureRecognizer:twoFingersTwoTaps];
消息方法twoFingersTwoTaps
- (void)twoFingersTwoTaps {
NSLog(@"Action: Two fingers, two taps");
}
3、一个手指向上、向下擦碰手势
// 向上擦碰
UISwipeGestureRecognizer *oneFingerSwipeUp =
[[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerSwipeUp:)] autorelease];
[oneFingerSwipeUp setDirection:UISwipeGestureRecognizerDirectionUp];
[[self view] addGestureRecognizer:oneFingerSwipeUp];
- (void)oneFingerSwipeUp:(UISwipeGestureRecognizer *)recognizer
{
CGPoint point = [recognizer locationInView:[self view]];
NSLog(@"Swipe up - start location: %f,%f", point.x, point.y);
}
// 向下擦碰
UISwipeGestureRecognizer *oneFingerSwipeDown =
[[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerSwipeDown:)] autorelease];
[oneFingerSwipeDown setDirection:UISwipeGestureRecognizerDirectionDown];
[[self view] addGestureRecognizer:oneFingerSwipeDown];
- (void)oneFingerSwipeDown:(UISwipeGestureRecognizer *)recognizer
{
CGPoint point = [recognizer locationInView:[self view]];
NSLog(@"Swipe down - start location: %f,%f", point.x, point.y);
}
4、旋转手势
UIRotationGestureRecognizer *twoFingersRotate =
[[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingersRotate:)] autorelease];
[[self view] addGestureRecognizer:twoFingersRotate];
- (void)twoFingersRotate:(UIRotationGestureRecognizer *)recognizer
{
// Convert the radian value to show the degree of rotation
NSLog(@"Rotation in degrees since last change: %f", [recognizer rotation] * (180 / M_PI));
}
5、向里或向外捏的手势
UIPinchGestureRecognizer *twoFingerPinch =
[[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerPinch:)] autorelease];
[[self view] addGestureRecognizer:twoFingerPinch];
- (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer
{
NSLog(@"Pinch scale: %f", recognizer.scale);
}
使用iOS手势UIGestureRecognizer的更多相关文章
- iOS手势UIGestureRecognizer的使用失效问题
问题:视图正常展示在界面中,父层是放在window上的,底部的一个控件的点击事件失效(所有设置都正常) 解决思路:虽然视图能够正常展示,但是发现父类视图的底部尺寸比子类的视图的尺寸小,也就是说上层视图 ...
- iOS手势UIGestureRecognizer的使用及手势冲突的解决办法【转】
转自:iOS开发中的手势体系——UIGestureRecognizer分析及其子类的使用 关于手势的一篇很好的帖子,转载过来免得丢失.你可能最感兴趣的是手势间的互斥处理,那么就搜索 4.手势间的互斥处 ...
- IOS手势UIGestureRecognizer
UIGestureRecognizer是一个抽象类,定义了所有手势的基本行为,它有6个子类处理具体的手势: 1.UITapGestureRecognizer (任意手指任意次数的点击) // 点击次数 ...
- 点击事件touches与ios的手势UIGestureRecognizer
.h文件 @property (weak,nonatomic) IBOutlet UILabel *messageLabel;@property (weak,nonatomic) IBOutlet U ...
- [BS-25] IOS中手势UIGestureRecognizer概述
IOS中手势UIGestureRecognizer概述 一.概述 iPhone中处理触摸屏的操作,在3.2之前是主要使用的是由UIResponder而来的如下4种方式: - (void)touches ...
- iOS手势学习UIGestureRecognizer & cocos2d 手势推荐
iOS手势学习UIGestureRecognizer & cocos2d 手势推荐 手势识别类型: UILongPressGestureRecognizer // 长按UIPanGestur ...
- ios手势
iOS 手势操作:拖动.捏合.旋转.点按.长按.轻扫.自定义 大 中 小 1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. i ...
- iOS手势处理
iOS手势处理 iOS手势有着如下几种: UITapGestureRecognizer UIPinchGestureRecognizer UIRotationGestureRecognizer UIS ...
- iOS Programming UIGestureRecognizer and UIMenuController
iOS Programming UIGestureRecognizer and UIMenuController A UIGestureRecognizer intercepts touches ...
随机推荐
- Metasploit启动
一.启动Kali的PostgreSQL服务 由于使用PostgreSQL作为数据库,因此,必须先运行它. root@kali:~# service postgresql start 使用ss -ant ...
- class bool
class bool(int): """ bool(x) -> bool Returns True when the argument x is true, Fal ...
- 利用UIImagePickerController或者利用UIKit的 UIGraphicsBeginImageContext保存图片
转载自:http://my.oschina.net/hmj/blog/99970 应用中有时我们会有保存图片的需求,如利用UIImagePickerController用IOS设备内置的相机拍照 ...
- 使用logmnr方法找回被误删除Oracle的数据的脚本
俗话说,常在河边走,哪有不湿鞋的.作为一个经常与数据库打交道的程序员,偶尔不小心误删除或误操作的数据也是在所难免的.如果是Oracle数据库,这里给您介绍一种从日志中找回数据的办法,下面这个地址是我以 ...
- HDU1963Investment(DP)
简单DP,题解见代码
- 利用一些码农Trick去搞一搞G和T的单词
根据自然语言处理中的Zipf统计定律,在自然语言的语料库里,一个单词出现的频率与它在频率表里的排名成反比.因此,我们有理由认为,可以根据这个频率表进行一下排序,以及purning.由于精力有限,没有足 ...
- iOS多线程总结
1.不要同时开太多的线程(1~3条线程即可,不要超过5条) 2.线程概念 1> 主线程 : UI线程,显示.刷新UI界面,处理UI控件的事件 2> 子线程 : 后台线程,异步线程 3.不要 ...
- Giraph之SSSP(shortest path)单机伪分布运行成功
所遇问题:Exception 1: Exception in thread "main" java.lang.IllegalArgumentException: "che ...
- C#调用存储过程详解
连接字符串: string conn = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].C ...
- android 工具类之图片加工
/** * 图片加工厂 * * @author way * */ public class ImageUtil { /** * 通过路径获取输入流 * * @param path * 路径 * @re ...