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

ios触摸事件三:UIResponder

2015-12-19 13:30 453 查看
前面了解了想要响应事件就必须遵循UIResponder。那么UIResponder是怎么样的呢。让我们打开浏览器,输入https://developer.apple.com网址(苹果开发官网),点击右上角的放大镜在文本框内搜索”UIResponder Class Reference”。在搜索到的内容中点击UIResponder Class Reference。就可以查看响应的具体内容(不过需要略懂英语,略懂,,)。



我们可以看到 UIResponder 继承了oc的最基本的类NSObject。他的子类有很多:包括UIApplication、UIView、UIViewController等。在UIKit包里面。ios2.0以后的版本都可用

NS_CLASS_AVAILABLE_IOS(2_0) @interface UIResponder : NSObject {
@private
}

- (UIResponder*)nextResponder;   /*下一个响应者*/

- (BOOL)canBecomeFirstResponder;    // default is NO 是否可以称为响应者。默认是NO
- (BOOL)becomeFirstResponder;   /*称为第一响应者*/

- (BOOL)canResignFirstResponder;    // default is YES 是否可以取消第一响应者。默认是yes
- (BOOL)resignFirstResponder;  /*取消第一响应者*/

- (BOOL)isFirstResponder; /*判断是否是第一响应者*/

/***一般所有的触摸事件都需要重写以下四个方法***/
/* 每一个响应者将要收到的不是 **touchesEnded:withEvent:**(触摸结束) 就是 **touchesCancelled:withEvent:** (触摸取消)消息*/
/* touch收到  **touchesBegan:withEvent:** (触摸开始)的时候开始处理*/
/*必须对手势取消的状态进行处理,避免程序崩溃*/
- (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;
-
@end

/*UIResponder的一个类目*/
@interface UIResponder (UIResponderKeyCommands)
@property (nonatomic,readonly) NSArray *keyCommands NS_AVAILABLE_IOS(7_0); // 返回一个UIKeyCommand对象的数组
@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: