简单区分UIResponder与UIControl
2016-06-14 16:47
369 查看
UIResponder类:上承NSObject,下接UIView ,UIVIewController ,UIApplacation;响应点,压,滑;
UIControl类:上承UIView,下接UIButton等开关按钮;
主要区别在于:
前者,主要是响应某个动作,执行某个行为--
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event;
后者,在继承了前者的属性基础上,还能够相应某个动作,为某个对象,添加动作--
- (void) addTarget:(id)target action:(SEL)action forControlEvents(UIControlEvents)controlEvents
- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
返回值:YES 接受用户通过addTarget:action:forControlEvents添加的事件继续处理。
返回值:NO 则屏蔽用户添加的任何事件
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 如果用户重写了该方法,则不会执行由用户添加的其他事件,直接屏蔽了用户的事件
触摸与事件:
1、- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
在UIView中判断触摸的点是否在UIView中起作用。可以实现一些非矩形的触摸事件。
例如:圆形,判断点到圆心的距离。
UIBezierPath,UITapGestureRecognizer等类是在sdk3.2及以后才可以使用的。
2、在UIWebView上的触摸事件处理方法:
方法(1)继承UIWindow,重写- (void)sendEvent:(UIEvent *)event
方法(2)使用UITapGestureRecognizer
UIGestureRecognizer http://www.cnblogs.com/iphone520/archive/2011/10/27/2226548.html
3、响应链
触摸事件的响应是从view->viewcontroller->superview->superViewcontroller->window->application,如果一直没有被处理,就被抛弃掉了。
在ios4中,touch事件只被最内层的视图响应。
但在ios5中,它可能从内层向外挨个响应。
响应都链排列顺序大致与视图层次结构顺序相反。
4、分派事件
使用下面两个方法分派事件给响应者处理:
- (void)sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event;
- (void)sendActionsForControlEvents:(UIControlEvents)controlEvents; // send all actions associated with events
事件与操作的区别:事件报告对屏幕的触摸;操作报告对控件的操纵。
5、事件处理
调用[self.nextResponder touchesBegan:touches withEvent:event];把事件传递
参考 http://blog.csdn.net/iefreer/article/details/4754482
6、- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
Returns the farthest descendant of the receiver in the view hierarchy (including itself) that contains a specified point.
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event;
UIControl类:上承UIView,下接UIButton等开关按钮;
主要区别在于:
前者,主要是响应某个动作,执行某个行为--
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event;
后者,在继承了前者的属性基础上,还能够相应某个动作,为某个对象,添加动作--
- (void) addTarget:(id)target action:(SEL)action forControlEvents(UIControlEvents)controlEvents
- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
返回值:YES 接受用户通过addTarget:action:forControlEvents添加的事件继续处理。
返回值:NO 则屏蔽用户添加的任何事件
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 如果用户重写了该方法,则不会执行由用户添加的其他事件,直接屏蔽了用户的事件
触摸与事件:
1、- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
在UIView中判断触摸的点是否在UIView中起作用。可以实现一些非矩形的触摸事件。
例如:圆形,判断点到圆心的距离。
UIBezierPath,UITapGestureRecognizer等类是在sdk3.2及以后才可以使用的。
2、在UIWebView上的触摸事件处理方法:
方法(1)继承UIWindow,重写- (void)sendEvent:(UIEvent *)event
方法(2)使用UITapGestureRecognizer
UIGestureRecognizer http://www.cnblogs.com/iphone520/archive/2011/10/27/2226548.html
3、响应链
触摸事件的响应是从view->viewcontroller->superview->superViewcontroller->window->application,如果一直没有被处理,就被抛弃掉了。
在ios4中,touch事件只被最内层的视图响应。
但在ios5中,它可能从内层向外挨个响应。
响应都链排列顺序大致与视图层次结构顺序相反。
4、分派事件
使用下面两个方法分派事件给响应者处理:
- (void)sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event;
- (void)sendActionsForControlEvents:(UIControlEvents)controlEvents; // send all actions associated with events
事件与操作的区别:事件报告对屏幕的触摸;操作报告对控件的操纵。
5、事件处理
调用[self.nextResponder touchesBegan:touches withEvent:event];把事件传递
参考 http://blog.csdn.net/iefreer/article/details/4754482
6、- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
Returns the farthest descendant of the receiver in the view hierarchy (including itself) that contains a specified point.
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event;
相关文章推荐
- jQuery中的常用事件总结
- C#实现WinForm捕获最小化事件的方法
- c#事件使用示例详解
- C#中的事件介绍
- C#实现自定义双击事件
- extjs 为某个事件设置拦截器
- Android开发系列三之窗口的常用事件
- jQuery阻止同类型事件小结
- jQuery bind事件使用详解
- jQuery支持添加事件的日历特效代码分享(3种样式)
- C#中委托和事件的区别实例解析
- SQLSERVER中得到执行计划的两种方式
- C#中事件的动态调用实现方法
- ASP.NET中实现定制自己的委托和事件参数类
- C#处理Paint事件的方法
- javascript下利用for( in )语句 获得所有事件名称的代码
- 关于JavaScript与HTML的交互事件
- jQuery绑定事件监听bind和移除事件监听unbind用法实例详解
- JavaScript 学习笔记(十六) js事件
- JQuery实现表格动态增加行并对新行添加事件