触摸,事件,UIGestureRecognizer

来源:互联网 发布:淘宝内衣买家秀大尺度 编辑:程序博客网 时间:2024/05/17 08:49


1.UIView的触摸控制是在UIView中编程处理,不是在UIViewController中编程处理。


2.独占触摸模式。。。


3.- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event

   在UIView中判断触摸的点是否在UIView中起作用。可以实现一些非矩形的触摸事件。

   例如:圆形,判断点到圆心的距离。

   UIBezierPath,UITapGestureRecognizer等类是在sdk3.2及以后才可以使用的。


4.在UIWebView上的触摸事件处理方法:

方法(1)继承UIWindow,重写- (void)sendEvent:(UIEvent *)event

方法(2)使用UITapGestureRecognizer

                 UIGestureRecognizer   http://www.cnblogs.com/iphone520/archive/2011/10/27/2226548.html

 

5.响应链

  触摸事件的响应是从view->viewcontroller->superview->superViewcontroller->window->application,如果一直没有被处理,就被抛弃掉了。

  在ios4中,touch事件只被最内层的视图响应。

  但在ios5中,它可能从内层向外挨个响应。

  响应都链排列顺序大致与视图层次结构顺序相反。


6.跟踪触摸

  UIControl中处理触摸的4个方法:

- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event;
- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event;
- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event;
- (void)cancelTrackingWithEvent:(UIEvent *)event;   // event may be nil if cancelled for non-event reasons, e.g. removed from window

 

7.分派事件

   使用下面两个方法分派事件给响应者处理:

- (void)sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event;
- (void)sendActionsForControlEvents:(UIControlEvents)controlEvents;                        // send all actions associated with events

  事件与操作的区别:事件报告对屏幕的触摸;操作报告对控件的操纵。


8.事件处理

   调用[self.nextResponder touchesBegan:touches withEvent:event];把事件传递

   参考 http://blog.csdn.net/iefreer/article/details/4754482


9.  - (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;


11离散手势,连续手势


12UIGestureRecognizer

    动作解释:

    •    tap:轻触
    •    long press:在一点上长按
    •    pinch:两个指头捏或者放的操作
    •    pan:拖动,慢速移动
    •    swipe:轻扫,快速滑动
    •    rotation:手指反向操作

    自定义手势,继承UIGestureRecognizer

    UISwipeGestureRecognizer

    轻扫手势也可以设置numberOfTouchesRequired值,设置同时触摸的手指数;

    iPhone风格不善于长按,却有长按手势识别器类UILongPressGestureRecognizer



13.requireGestureRecognizerToFial,设置优先级

     requireGestureRecognizerToFail,指定某一个 recognizer,即便自己已经滿足條件了,也不會立刻触发,会等到该指定的 recognizer 确定失败之后才触发。


14.UIPinchGestureRecognizer

      




15.添加到UINavigationViewController中的,或弹出的ViewController都能收到didRotateFromInterfaceOrientation,可能是UINavigationViewController已经内部向子视图传递消息了。

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    return YES;
}

    UINavigationViewController的view必须加入到window中。


16.  监听UIApplicationDidEnterBackgroundNotification
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveLastReadPosition) name:UIApplicationDidEnterBackgroundNotification object:nil]; 



转载地址:http://blog.csdn.net/andyweike/article/details/6687570