开发者

Detecting touches with stacked Views & passing Touch events from a UIScrollView

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 f开发者_JAVA百科or 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.


You might be able to use [super touchesBegan:withEvent:] to help solve the problem.

Depending on what your trying to do you might be able to use UIGestureRecognizer to capture the touch events.

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

doubleTapGestureRecognizer.numberOfTapsRequired = 2; //change value to 1 for single taps
[self addGestureRecognizer:doubleTapGestureRecognizer];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜