IOS Bug Log-userinteractionenabled

Source: Internet
Author: User

Today do a nine Gongge password project, set button of the selected state, how all wrong, and later found that the role of this property

[Btn setbackgroundimage:[uiimage imagenamed:@ "Gesture_node_normal"] forstate:uicontrolstatenormal];

btn.userinteractionenabled = NO;

Set the selected picture

[Btn setbackgroundimage:[uiimage imagenamed:@ "gesture_node_highlighted"] forstate:uicontrolstateselected];

If you want to toggle the value of the button's selected, you must set such a property otherwise interactive as enabled as the interactive

The

property is  

        The property value is a Boolean type, as described by the name of the property itself, which determines whether UIView accepts and responds to user interaction. &NBSP

        When the value is set to No, UIView ignores user events, such as touch and keyboard, that should have occurred to them. and remove these events from the message queue. When the value is set to Yes, these user events are normally distributed to the UIView itself (the premise event does occur on the view), and UIView responds to these events in accordance with previously registered event-handling methods.  

        in an animation execution process, all uiview that are included in the animation are temporarily blocked from user interaction. Regardless of whether each UIView itself userinteractionenabled the property value at this time is yes or No. However, when you configure an animation, you can prevent this behavior by adding the uiviewanimationoptionallowuserinteraction option, so that UIView still responds to user events even during animation execution.  

A simple principle describing  

        Developers who are familiar with the iOS message response chain understand the basic process of hit-testing, and we can simply understand that in a user's touch interaction, Hit-test determines the entire view hierarchy of application. Exactly which view to receive and handle the event. Its basic screening process can be rough described as:  

    The
    1. Touch event occurs, creating a Uievent object
    2. invokes the hittest:withevent of each view by layer, according to the view hierarchy of the application: method, and passing in the event object, View is based on Hittest:withevent: method and determines whether touch points are included in their own bounds;
    3. If the view's bounds contains a touch point, the view traverses its own subview. and call each Subview's Pointinside:withevent: method to further determine whether the touch event occurs on its own, or on its own subview.
    4. repeats the second, three steps, and filters out the view object that eventually accepts the touch event


Our focus is on the 3rd step of the filtering process, which is affected by the Userinteractionenabled property setting when the view calls the Hittest:withevent: method, and if the value of the view's property is set to No, the Even if the final touch point is actually included in the view's bounds, the view ignores the touch event, and of course userinteractionenabled's settings are just one of the touch filtering conditions, and other considerations are included in the real screening process. So also refer to Hittest:withevent: The specific method described, but the above describes the individual feel enough to understand the basic principles of the userinteractionenabled attribute.

Overrides for special subclasses

The default value of the Userinteractionenabled property is yes, but the property is overwritten in some subclasses of UIView and its default value is set to No, where Uiimageview and Uilabel are such classes. The Userinteractionenabled property has a simple description in both the Uiimageview and Uilabel documents. In the actual interface development process, we often use Uiimageview to simulate buttons or other display areas that can respond to user touch events, and to add event responses to them through gesture, so in order to ensure that events are properly accepted, We have to show that the value of the userinteractionenabled of the Uiimageview object is set to Yes.

IOS Bug Log-userinteractionenabled

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.