How to prevent view resizing/transform when UINavigationBar hides/shows

跟風遠走 提交于 2019-12-04 21:29:07

问题


I have an application with a tab bar and a navigation bar. I push a view controller that is used to show photos, one at a time. It initially shows the bars and forward/back controls; after a delay, these hide, using setNavigationBarHidden:animated: and a custom transform (CGAffineTransformMakeTranslation) on the tab bar. This works, but the view controllers view , which shows the photo, leaps up and down. The same is true if I leave the tab bar out of the equation.

How can I prevent the UINavigationBar from moving my view around? I would like the photo to stay fixed in the screen, with the nav bar dropping down over the top segment of it.


回答1:


I know this is an old question, but I accomplished that by disabling 'Autoresize Subviews' in Interface Builder




回答2:


Had this issue and fixed it with a class that inherited from UINavigationController

-(void)viewWillAppear:(BOOL)animated
{
    self.navigationBar.translucent = YES;
}

Worked great for me, didn't had to set style to UIBarStyleBlackTranslucent. So it did kept my colors.




回答3:


[[navigationController navigationBar] setBarStyle:UIBarStyleBlackTranslucent];
[[navigationController navigationBar] setAutoresizesSubviews:NO];

this seemed to do the trick for me!




回答4:


I haven't been able to find a proper way to handle this except to set the navigationBar style to translucent as in:

theNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;

Other than creating another navigation bar and adding buttons to them, that's the best (and it seems to be what Apple does as well in it's Photo app)



来源:https://stackoverflow.com/questions/2864978/how-to-prevent-view-resizing-transform-when-uinavigationbar-hides-shows

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