iOS触摸事件学习

iOS触摸事件详解
本文详细介绍了iOS中触摸事件的处理方法,包括触摸开始、移动、结束及取消等不同阶段对应的事件处理函数。此外还介绍了如何从触摸事件中获取关键信息如位置、视图、点击次数等。

部分内容摘自:http://www.cnblogs.com/kenshincui/p/3950646.html

触摸事件  
- (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; 触摸意外取消时执行(例如正在触摸时打入电话);

在事件处理函数中从touches(NSSet*)中获得UITouch对象,通过该对象来获得触摸时相应的状态参数等,常用的方法及属性有:

1. - (CGPoint)locationInView:(UIView *)view

Returns the current location of the receiver in the coordinate system of the given view.

返回“当前触点”在给定视图中的坐标


2. - (CGPoint)previousLocationInView:(UIView *)view

Returns the previous location of the receiver in the coordinate system of the given view.

返回“上一个触点”在给定视图中的坐标


3.@property(nonatomic, readonly, retain) UIView *view

The view in which the touch initially occurred. (read-only)

发生触发的视图(只读)


4.@property(nonatomic, readonly, retain) UIWindow *window

The window in which the touch initially occurred. (read-only)

发生触发的窗口(只读)


5.@property(nonatomic, readonly) NSUInteger tapCount

The number of times the finger was tapped for this given touch. (read-only)

点击次数(只读)短期内


6.@property(nonatomic, readonly) NSTimeInterval timestamp

The time when the touch occurred or when it was last mutated. (read-only)

触摸产生或变化的时间戳(只读)


7.对UIEvent对象:

- (NSSet *)touchesForView:(UIView *)view

Returns the touch objects that belong to a given view for the event represented by the receiver.

返回位于给定的视图的触摸集合。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值