Can you set scroll inserts for container controllers?

I have a container controller that displays a row of data right under the linker.

I want the child controller of this container controller to scroll behind this panel, as well as any navigation bar and status bar. However, it seems that when UIKit automatically configures controller scroll inserts, it only considers the length of the top layout guide.

Is it possible to say that scroll inserts should be the top layout + height of my panel? I know that people are going to suggest that I set automaticallyAdjustsScrollViewInsets = NO , but I already tried this. The problem is that I cannot reproduce exactly when UIKit sets the content inserts, and so I get all kinds of weird edge cases that break the inserts. The most striking example is the UITableViewController, where, since I set the content inserts manually, the update control is sometimes not in the correct position, and when I finish the update, the inserts in the scroll view are set to {0, 0}, so the contents are hidden in my bar and panel navigation.

UPDATE: All the magic seems to be inside the _setNavigationControllerContentInsetAdjustment methods on the UIViewController and _computeAndApplyScrollContentInsetDeltaForViewController on the UINavigationController.

It appears that only the navigation controller is trying to customize the scroll inserts and computes the inserts based on the top and bottom layouts. It passes these inserts to the view controller, which then adds / subtracts the inserts from the scroll and takes into account which inserts of the navigation content were installed earlier. This ensures that if anyone else changes the content attachments between them and now that the navigation controller last modified the inserts, they will not override the intermediate changes.

+6
source share
1 answer

My solution was to set automaticallyAdjustsScrollViewInsets = NO and handle the content attachment settings myself.

I created a category on the UIViewController that kept track of any existing inserts that were set this way whenever I set up the inserts to see the scroll view below my custom UIView I would not lose any information like pasting content for a UITableViewController with active control updates inside it.

After that, the last task was to determine where to install custom inserts, and after many experiments, I found that - (void)viewDidLayoutSubviews is the best place to do this.

FDScrollingTabBarController is the container controller in which I implemented this solution.

+2
source

Source: https://habr.com/ru/post/971057/


All Articles