简单区分UIResponder与UIControl

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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值