UIButton inside UIScrollView, inside UIScrollview

2019-07-25 17:20发布

问题:

Controller A's view contains a UIScrollview which contains a UIButton. The content scrolls vertically and the button works fine.

Controller B's view contains a UIScrollview for paging left and right.

When I place my Controller A view inside the scroll view of Controller B's the UIButton stops working.

I can't 'de-nest' the scrollviews because they are managed by independent controllers - and paging is only required under certain circumstances.

Why does Controller B stop the button from working?

回答1:

From the UIViewController docs:

Note: You should not use view controllers to manage views that fill only a part of their window—that is, only part of the area defined by the application content rectangle. If you want to have an interface composed of several smaller views, embed them all in a single root view and manage that view with your view controller.

The OS only bothers to send events to a single UIViewController, whichever one it thinks is active and filling the window. Only that one view controller is sure to get events including rotation method calls and memory warnings.