您的位置:首页 > 产品设计 > UI/UE

ios触摸事件一 :UIEvent

2015-12-18 10:01 537 查看
手机事件一般分为:

运动事件(如手机摇动等)、远程控制事件(如蓝牙等)、触摸事件(常用的屏幕点击)。

IOS通过检测用户的手势并对其做出回应,即可以与用户手势交互。

触摸的概念就不在解释了。触摸是在UIView(用户屏幕上的可视view)上进行的。实际上所有的UI控件都是直接继承或者间接继承自UIView,所以,所有的UI控件都可以产生触摸事件。 注意 import UIKit.

当用户触摸屏幕时,事件会被封装成一个UIEvent实例,其包含了触摸事件的相关信息。event实例中包含着若干UITouch实例,一个touch表示一个触点(手指)。

首先了解一下UITouch类。

官方文档解释:A UITouch object represents the location, size, movement, and force of a finger on the screen for a particular event. The force of a touch is available starting in iOS 9 on devices that support 3D Touch.

UITouch就表示了一个触点(手指触摸点)的响应属性。可以从其得到相关的数据,以便于处理。ios9增加了3Dtouch的效果。多了一个force(力度)属性。

当用户点击屏幕后,响应者会获取一个UIEvent对象,我们可以从其实例中获得UITouch对象。

A touch object includes accessors for:

The view or window in which the touch occurred

The location of the touch within the view or window

The approximate radius of the touch

The force of the touch (on devices that support 3D Touch)

UITouch类的常用属性: 继承了NSObject

(UITouch —–> NSObject)

NS_CLASS_AVAILABLE_IOS(2_0) @interface UITouch : NSObject

@property(nonatomic,readonly) NSUInteger          tapCount;   //获取很短时间内点击的次数。只读。
- (CGPoint)locationInView:(UIView *)view; //返回当前触点在指定view(参数)的位置。中心点,针对view坐标系
- (CGPoint)previousLocationInView:(UIView *)view; //该方法记录了前一个的坐标值,返回一个CGPoint类型的值,表示触摸在view这个视图上的位置,返回的位置是针对view的坐标系的。
/*英语扫盲:previous |ˈpriːvɪəs| adj : 先前的。*/
/*!!学号一门外语很重要!!*/
@end


再来了解一下UIEvent类。


官方解释:A UIEvent object (or, simply, an event object) represents an event in iOS. There are three general types of event: touch events, motion events, and remote-control events.

远程控制事件: Remote-control events allow a responder object to receive commands from an external accessory or headset so that it can manage manage audio and video—for example, playing a video or skipping to the next audio track. Motion events were introduced in iOS 3.0 and remote-control events in iOS 4.0.

UIEvent类的常用属性:

(UIEvent —-> NSObject)

@interface UIEvent : NSObject

- (NSSet *)allTouches; //返回所有的touch (Set集合)!!!常用
- (NSSet *)touchesForWindow:(UIWindow *)window; //返回指定window上的一组touch(不常用)
- (NSSet *)touchesForView:(UIView *)view;//返回事件的属于指定view的一组touch(不常用)
- (NSSet *)touchesForGestureRecognizer:(UIGestureRecognizer *)gesture `NS_AVAILABLE_IOS(3_2);//返回指定手势所使用的一组touch(不常用)

@end


提示:以上内容均为个人理解,若有偏颇,望指正。多谢
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: