zoukankan      html  css  js  c++  java
  • Touch Events and UIResponder(19)

    NSValue valueWithNonretainedObject 

    http://stackoverflow.com/questions/8748736/weak-object-in-an-nsdictionary

    http://stackoverflow.com/questions/3618479/how-to-create-weak-reference-in-objective-c

    setNeedsLayout

    setNeedsDisplay

     

    [[self nextResponder] touchesBegan:touches withEvent:event]; 

    For the More Curious: UIControl 

    UIControl : UIView  ---->UIView : UIResponder

    The class UIControl is the superclass for several classes in Cocoa Touch, including UIButton and UISlider. We’ve seen how to set the targets and actions for these controls. Now we can take a closer look at how UIControl overrides the same UIResponder methods you implemented in this chapter.

    In UIControl, each possible control event is associated with a constant. Buttons, for example, typically send action messages on the UIControlEventTouchUpInside control event. A target registered for this control event will only receive its action message if the user touches the control and then lifts the finger off the screen inside the frame of the control. Essentially, it is a tap.

    For a button, however, you can have actions on other event types. For example, you might trigger a method if the user removes the finger inside or outside the

    frame. Assigning the target and action programmatically would look like this: 

    [rButton addTarget:tempController action:@selector(resetTemperature:)

    forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside]; 

    Now consider how UIControl handles UIControlEventTouchUpInside.

    // Not the exact code. There is a bit more going on!
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    // Reference to the touch that is ending UITouch *touch = [touches anyObject];

    // Location of that point in this control's coordinate system CGPoint touchLocation = [touch locationInView:self];

    // Is that point still in my viewing bounds?
    if (CGRectContainsPoint([self bounds], touchLocation)) {

    // Send out action messages to all targets registered for this event!

    [self sendActionsForControlEvents:UIControlEventTouchUpInside]; } else {

    // The touch ended outside the bounds, different control event

    [self sendActionsForControlEvents:UIControlEventTouchUpOutside]; }

     

    So how do these actions get sent to the right target? At the end of the UIResponder method implementations, the control sends the message sendActionsForControlEvents: to itself. This method looks at all of the target-action pairs the control has, and if any of them are registered for the control event passed as the argument, those targets are sent an action message.

    However, a control never sends a message directly to its targets. Instead, it routes these messages through the UIApplication object. Why not have controls send the action messages directly to the targets? Controls can also have nil-targeted actions. If a UIControl’s target is nil, the UIApplication finds the first responder of its UIWindow and sends the action message to it. 

  • 相关阅读:
    eclipse3.2 汉化 汉化包下载
    JAXB 操作XML 与 Object
    具体解释三层架构图
    四个好看的CSS样式表格
    LinearGradient线性渲染
    JAVA wait(), notify(),sleep具体解释
    System.currentTimeMillis();
    nefu117 素数个数的位数,素数定理
    java jdk缓存-128~127的Long与Integer
    js正則表達式语法
  • 原文地址:https://www.cnblogs.com/zhangjl/p/3668239.html
Copyright © 2011-2022 走看看