iOS中的事件
一 : 用户在使用APP过程中,会产生各种各样的触摸事件
二 :IOS中的事件可以分为三大类
响应者对象
一 :在IOS中不是任何对象都能处理事件只有继承了UIResponder的对象才能接受并且处理响应事件,一般称之为"响应者对象"
二 :UIApplocation、UIViewControll、UIView、都继承自UIResponder,因此他们都是响应者对象,都能够接受并且处理响应事件,一般情况下的View不支持多点触碰,需要设置multipleTouch属性
UIResponder
UIResponder内部提供了一下方法来处理事件。
// 普通UIView实现以下方法
效果
做法 A
// 触摸对象
UITouch* touch = [touches anyObject];
// 取位置
CGPoint point = [touch locationInView:self.superview];
// 改坐标
self.center = point;
做法B
// 触摸对象
UITouch* touch = [touches anyObject];
// 取位置
CGPoint current = [touch locationInView:self];
// 上一个触摸点
CGPoint previous = [touch previousLocationInView:self];
// 改坐标
CGPoint center = self.center;
center.x+= current.x - previous.x;
center.y+= current.y - previous.y;
self.center = center;
@property(nonatomic,readonly) UIEventType type;
@property(nonatomic,readonly) UIEventSubtype subtype;
@property(nonatomic,readonly) NSTimeInterval timestamp;
touches和event参数
UITouch的属性
@property(nonatomic,readonly,retain) UIWindow *window;
@property(nonatomic,readonly,retain) UIView *view;
@property(nonatomic,readonly) NSUInteger tapCount;
@property(nonatomic,readonly) NSTimeInterval timestamp;
@property(nonatomic,readonly) UITouchPhase phase;
UITouch* touch = [touches anyObject];
NSLog(@"%@ %d",[touch view],[touch tapCount]);