UITapGestureRecognizer only triggered for starting area of UIScrollView

那年仲夏 提交于 2019-12-11 13:46:41

问题


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.


回答1:


Please check your contentview size or setbackground color for scrollview and contentview. Contenview size is not increasing i think.




回答2:


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



来源:https://stackoverflow.com/questions/37922429/uitapgesturerecognizer-only-triggered-for-starting-area-of-uiscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!