How to let a touch event penetrate a view

Source: Internet
Author: User

How to let a touch event penetrate a view

By accident, it is very easy to block or let a touch event penetrate a view.

Symptom:

Source code:

//// Viewcontroller. M // userinteraction /// created by youxianming on 14/10/23. // copyright (c) 2014 youxianming. all rights reserved. // # import "viewcontroller. H "@ interface viewcontroller () @ end @ implementation viewcontroller-(void) viewdidload {[Super viewdidload]; // create a button uibutton * button = [[uibutton alloc] initwithframe: Self. view. bounds]; [Button addtarget: Self action: @ selector (buttonevent :) forcontrolevents: uicontroleventtouchupinside]; [self. view addsubview: button]; // view uiview * testview = [[uiview alloc] initwithframe: Self. view. bounds]; [self. view addsubview: testview]; testview. userinteractionenabled = yes;}-(void) buttonevent :( uibutton *) button {nslog (@ "Touch event");} @ end

In fact, the principle is very simple. A touch event is accepted or blocked by the view. It is determined by this parameter, that is, userinteractionenabled.

Therefore, when you want to block an event and prevent it from penetrating, set the userinteractionenabled of the overwritten view to No.

 

How to let a touch event penetrate a view

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.