0

I'm trying to close a pop-up menu if the user selects anywhere EXCEPT with-in the bounds of the pop-up itself. In other words, they select the background, the pop-up closes.

I currently have a RootViewController that loads a UIView with a bunch of other UI Elements. At one point, a pop-up (custom) menu is rendered - this is a separate UIViewController with associated .xib. Its loaded on the screen by:

    SectionsChooserViewController *cv = [[SectionsChooserViewController alloc] initWithNibName:@"SectionsChooserViewController" bundle:[NSBundle mainBundle]];
    cv.view.frame = CGRectMake(584, 391, 314, 346);
    cv.delegate = self;     

This view occupies only a small portion of the screen. So added detect code for touches to this view will only register the callback if you're ON the view.

If I don't handle touches in the "SectionsChooserViewController" and instead implement the touchesBegan in the rootViewController (which loads the "SectionsChooser...") it doesn't get called for 90% of the view because the UIScrollView's that I have seem to register the touch and not pass it on.

Is there a way to make the UIScrollView pass the touch event?

Edit: At least I think the UIScrollView's are taking the touch event. I'm not sure - I have nearly 20 UI Controls on the page.

Edit: Ok, it is the UIScrollView. If I turn off interaction-enabled on both scrollView's the UIView will get the touches, but this breaks the UIScrollViews - so that won't work.

4

1 回答 1

0

您也许可以[super touchesBegan:withEvent:]用来帮助解决问题。

根据您尝试执行的操作,您可能可以使用它UIGestureRecognizer来捕获触摸事件。

UITapGestureRecognizer *doubleTapGestureRecognizer = [[UITapGestureRecognizer alloc]
                        initWithTarget:self action:@selector(handleDoubleTap:)];

doubleTapGestureRecognizer.numberOfTapsRequired = 2; //change value to 1 for single taps
[self addGestureRecognizer:doubleTapGestureRecognizer];
于 2011-05-27T21:51:19.567 回答