[英]Navigationbar position reset when turn back to foreground
I set my navigation bar in my first ViewContoller at viewWillAppear
我在
viewWillAppear
第一个ViewContoller中设置了导航栏
self.navigationController.navigationBar.frame = CGRectMake(0.0, 64.0, self.navigationController.view.bounds.size.width, 44.0);
It let me put a logo above the bar . 它让我在吧台上面放了一个标志。
But when I turn the app to background and turn back , the navigationbar position reset to the top . 但是,当我将应用程序转到背景并返回时,导航栏位置将重置为顶部。
I have tried addObserver that catch UIApplicationWillEnterForegroundNotification
and set the frame of navigationbar again . 我已经尝试了捕获
UIApplicationWillEnterForegroundNotification
addObserver并再次设置导航栏的框架。 But it's not working . 但它不起作用。
Please help , thanks a lot . 请帮助,非常感谢。
you can try to change the appearance of the NavigationBar
and it will reflect allover the app 您可以尝试更改
NavigationBar
的外观,它将反映整个应用程序
[[UINavigationBar appearance] setFrame:];
and you can change its background image if you want 如果你愿意,你可以改变它的背景图像
[[UINavigationBar appearance] setBackgroundImage:forBarMetrics:];
I had found the solution. 我找到了解决方案。
Subclass UINavigationBar. 子类UINavigationBar。
implement the - (CGSize)sizeThatFits:(CGSize)size
method to change navigation bar size. 实现
- (CGSize)sizeThatFits:(CGSize)size
方法来改变导航栏的大小。
such as 如
- (CGSize)sizeThatFits:(CGSize)size {
CGSize newSize = self.window.bounds.size ;
newSize.height = 91;
return newSize;
}
It works perfect. 它完美无缺。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.