9.1 触摸和手势:触摸的基本概念
来源:互联网 发布:淘宝店铺动态 编辑:程序博客网 时间:2024/04/28 03:35
==========无限互联IOS视频学习笔记=====UI高级=====
9.1 触摸和手势:触摸的基本概念
9.2 触摸和手势:单击双击、移动视图
9.3 触摸和手势:捏合手势
1.事件类型
·在iOS上,事件有多种形式:
·触摸事件
·运动事件
·远程控制事件
2.事件处理的方法
响应者类通过复写以下方法,可以监听触摸事件
// 当⼀个或多个手指触碰屏幕时
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
// 当⼀个或多个手指在屏幕上移动时
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
// 当⼀个或多个手指离开屏幕时
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
// 当触摸序列被诸如电话呼入这样的系统事件所取消时
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
3. UITouch触摸对象
4·UITouch类中常用属性
window:
触摸产⽣时所处的窗⼝。
view:
触摸产⽣时所处的视图。
tapCount:
轻击(Tap)操作和鼠标的单击操作类似,tapCount表⽰短时间内轻击屏幕的次数。因此可以根据tapCount判断单击、双击或更多的轻击。
timestamp:
时间戳记录了触摸事件产生或变化时的时间。单位是秒。
phase:
触摸事件在屏幕上有⼀个周期,即触摸开始、触摸点移动、触摸结束,还有中途取消。⽽通过phase可以查看当前触摸事件在⼀个周期中所处的状态。phase是UITouchPhase类型的,这是⼀个枚举配型,包含了
· UITouchPhaseBegan(触摸开始)
· UITouchPhaseMoved(接触点移动)
· UITouchPhaseStationary(接触点⽆移动)
· UITouchPhaseEnded(触摸结束)
5.UITouch类中常用方法
- (CGPoint)locationInView:(UIView *)view: 函数返回⼀个CGPoint类型的值,表⽰触摸在view这个视图上的位置,这⾥返回的位置是针对view的坐标系的。
- (CGPoint)previousLocationInView:(UIView *)view: 该⽅方法记录了前⼀个坐标值,函数返回也是⼀个CGPoint类型的值, 表⽰示触摸在 view这个视图上的位置,这⾥返回的位置是针对view的坐标系的.
触摸模拟代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; TouchView *touchView = [[TouchView alloc] initWithFrame:CGRectMake(0, 0, 320, 350)]; touchView.backgroundColor = [UIColor grayColor]; [self.window addSubview:touchView]; return YES;}
@interface TouchView : UIView
#import "TouchView.h"@implementation TouchView- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { // 开启触摸响应,默认是yes self.userInteractionEnabled = YES; // 开启多点触摸,默认NO; self.multipleTouchEnabled = YES; } return self;}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"touchesBegan"); UITouch *touch = [touches anyObject]; NSUInteger tapCount = touch.tapCount; NSLog(@"tapCount----%d", tapCount); }- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"touchesMoved");}- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"touchesEnded");}@end
- 9.1 触摸和手势:触摸的基本概念
- IOS UI初级-触摸与手势的基本概念和用法
- 轻击,触摸和手势
- 触摸事件和手势
- 触摸和手势
- iOS触摸和手势
- 手势和触摸事件
- 手势和触摸事件
- 处理触摸和手势
- 触摸和手势
- 使用复杂的触摸和手势UIXXGestureRecognizer
- IOS的触摸事件和手势处理
- 9.6 触摸和手势:手势识别器的使用
- 触摸手势
- 触摸手势
- IOS触摸事件和手势
- [IOS]触摸事件和手势
- 多点触摸和手势检测
- 海归进入贬值时代?
- tiny210(s5pv210)移植u-boot(基于 2014.4 版本)——移植u-boot-spl.bin(核心初始化)
- UVA11258- String Partition
- 队列中取最大值操作
- JSP常见的三个编译指令
- 9.1 触摸和手势:触摸的基本概念
- 注册时提示用户名小于3或者密码不匹配问题的临时办法
- MySQL-使用游标循环中断的问题
- poj 2117 去掉割点可以分得的联通图的个数模板
- TINY4412 驱动开发学习笔记整理--ARM体系结构篇
- Codeforces Round #254 (Div. 2)A. DZY Loves Chessboard
- UVa 620 Cellular Structure(DP)
- 马士兵struts2视频教程第十五集
- (转载)hadoop datanode启动不起来