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. 

  • 相关阅读:
    1130 host '***' is not allowed to connect to this MySQL server
    签名时出错,未能对....ext签名。SignTool Error: No certificates...
    C# 进制转换(二进制、十六进制、十进制互转)
    在安装32位Oracle客户端组建的情况下以64位模式运行
    Vue中引入jQuery
    sql server数据库分离时,数据库右侧显示(单个用户)
    解决Typora图片显示问题
    Ruby日文手册翻译1
    Boost Graph Library 库小结1
    归并排序
  • 原文地址:https://www.cnblogs.com/zhangjl/p/3668239.html
Copyright © 2011-2022 走看看