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