1

My problem is about tap detection.

I have a uiviewcontroller and there are some controls on uiview (labels, buttons, tableview, imageview, etc..)

When I tap the uibutton I display a small uiview (200x150), if the user taps the uibuttons in smallview I hide the smallview.

But I can't hide the uiview if the user taps the background.
I tried this code..

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    //NSLog(@"Touches began.");
    [self hideShareView];
}

It doesn't work if I tap the another button in the uiviewcontrols view.

I just want my uiviewcontrol's uiview to react first.
I think its about firstResponder but I dont know how to set it first.

edit: i want it to work like a uiPopover in ipad.

PhearOfRayne
  • 4,990
  • 3
  • 31
  • 44
kodcu
  • 91
  • 2
  • 9

3 Answers3

1

I believe that the correct approach is to add a new transparent UIView when you display your "smallview". You should add a UITapGestureRecognizer to that UIView, in order to trigger the desired selector when the tap is detected. Also, you must ensure that the views are arranged properly, with your smallview being the one at the top, the transparent UIView being immediately below and the rest of the view hierarchy below the transparent UIView.

Finally, you should ensure to remove the transparent UIView from your view hierarchy at the same time that you remove your smallview.

Does that make sense?

flainez
  • 11,797
  • 1
  • 18
  • 16
0

try your hands with bringing your small view (i.e. shareview) to front or sent your main view behind your small view.

If it still doesn't work & you don't want your main view to perform any action when smallview is opened then try

[<YOUR_MAIN_VIEW> setUserInteractionEnabled:NO]; , but MAKE SURE you can do this only when you don't want your main view to perform any action when smallview is opened

Niru Mukund Shah
  • 4,637
  • 2
  • 20
  • 34
0

Please have a look at this question (how-to-make-a-superview-intercept-button-touch-events), it does seem highly related.

Community
  • 1
  • 1
Nick Weaver
  • 47,228
  • 12
  • 98
  • 108
  • i tried the all solutions, but they didnt work for me. my uiviewcontrols have labels, buttons, uitableview, imageview, uiscrolview. if my smallview (shareView) is seen and i tap the any uilabel in my viewcontrollers, i can catch the tap event. but if i touch on the uitable, button, srollview or other any instance of my subclasses i cant the catch tap event in this event: -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event. it must be work like a UIPopOver. – kodcu Mar 13 '11 at 20:29