UITapGestureRecognizer only triggered for starting

2019-07-31 15:46发布

问题:

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