本文介绍了UITapGestureRecognizer 仅在 UIScrollView 的起始区域触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主视图控制器的 UIScrollView 中添加了几个子视图.每个子视图的视图控制器都有自己的点击识别器.问题是,只有在屏幕上的起始区域点击才能被识别.滚动视图并点击超出起始区域后,将不再调用点击处理程序.

这个 SO 帖子

如您所见,灰色和黄色边框

I have several sub views added to a UIScrollView in the main view controller. Each sub view's view controller has its own tap recognizer. The problem is, only tapping in the starting area on the screen is recognised. After scrolling the view and tapping beyond the starting area, the tapping handler will no longer be called.

This SO post UIButton in non-visible area of UIScrollView seems to be relevant but its solution description wasn't really clear to me...

A simple report project could be found at: dropbox link

Thanks.

解决方案

I have downloaded your project and see that the

SSubViewController *pvc = [SSubViewController controllerWithSubViewID:0];

pvc frame is out of bound

SSubViewController *pvc = [SSubViewController controllerWithSubViewID:0];
[self.scrollView addSubview:pvc.view];
[self addChildViewController:pvc];
[pvc.view setBackgroundColor:[UIColor grayColor]];
[pvc.view setFrame:CGRectMake(0, 0, 400, 200)];

[pvc didMoveToParentViewController:self];

SSubViewController *pvc1 = [SSubViewController controllerWithSubViewID:1];
[self.scrollView addSubview:pvc1.view];
[pvc1.view setBackgroundColor:[UIColor yellowColor]];
[self addChildViewController:pvc1];
[pvc1 didMoveToParentViewController:self];
[pvc1.view setFrame:CGRectMake(0, 400, 400, 200)];

Now see the Colours

As you can see Gray color, and Yellow color frame

这篇关于UITapGestureRecognizer 仅在 UIScrollView 的起始区域触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 09:20