How to resize a view when using the UINavigationController setToolbarHidden: animated:

I am using the UINavigationController toolbar. Before I show it, I resize my views so that they do not block on the toolbar (I set the frame of the current view controller view to a straight line located from the bottom of the navigationBar to the top of the toolbar .

But not all controllers of my kind have toolbarItems . Thus, when switching from a view controller that has elements (controller A) to one that does not work (controller B), I want to hide the toolbar. However, when I call setToolbarHidden:animated: in the B method of viewWillAppear:animated: the toolbar is animated during the transition and shows the UIWindow background behind it.

This also happens in the opposite direction: when moving from B to A (using the "Back" button) I want the toolbar to animate in order to display A toolbarItems , but since the view A does not extend to the bottom screen, UIWindow displayed during pop -transition.

Perhaps this was not the best description, so here is a screenshot:

Cmd-shift-3 rapid-fire FTW

I tried updating the frame in my viewWillDisappear:animated: method, but it does weird things, as it seems to be called inside the push animation block UINavigationController . Any insight would be appreciated.

Refresh . I tried to hide the toolbar in B viewDidAppear:animated: but the results were not perfect. Using this solution, the toolbar is not discarded until the transition to push is complete. Since B does not have any toolbarItems , elements of A will move to the left during the transition, leaving a blank toolbar on the screen before it disappears. In addition, when I return to the background, the UIWindow will be visible if I do not set the toolbar to the viewWillDisappear:animated: visible in B, which would mean that B should know that A has toolbarItems .

+4
source share
2 answers

Since I never found a satisfactory solution for this related to animation, I ended up leaving my views outside the toolbar so as not to show the window. If your controller view is a UITableView or UIScrollView, you can set its contentInset accordingly so that your content is not covered by the toolbar:

 UIEdgeInsets edgeInsets = [[self tableView] contentInset]; if (![[self navigationController] isToolbarHidden]) { edgeInsets.bottom = CGRectGetHeight([[[self navigationController] toolbar] frame]); } [[self tableView] setContentInset:edgeInsets]; 
0
source

Perhaps the best practice would be to call setToolbarHidden:animated: in B viewDidAppear ?

Or you can change the frame before pressing B on the navigation controller in the pushViewController:animated: method in a custom subclass of UINavigationController .

0
source

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


All Articles