ios触摸事件一 :UIEvent

本文介绍了iOS中的触摸事件,包括运动事件、远程控制事件和触摸事件。重点讲解了UIEvent和UITouch,UIEvent代表事件,包含触摸的相关信息,而UITouch表示触点的属性,如位置、大小、移动和力度(iOS 9及以上)。iOS中的所有UI控件都可响应触摸事件,开发者可以通过UIEvent和UITouch获取并处理用户手势。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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类。 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

提示:以上内容均为个人理解,若有偏颇,望指正。多谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值