我有一个问题,我有一个自定义导航栏,我已将高度更改为自定义值。我遇到的问题是当我退出应用程序,然后返回应用程序(再次变为活动状态)导航栏移动并重置它的高度。
我尝试运行相同的代码,用于在应用变为活动状态时更改导航栏高度,但这根本没有帮助。代码是:
[self.navigationBar setBounds:[self getBarHeightAdjustment]];
- (CGRect) getBarHeightAdjustment {
CGFloat height= 80;
if ([UIApplication isPhone]) {
height = 45;
}
return CGRectMake(self.navigationBar.bounds.origin.x, self.navigationBar.bounds.origin.y, self.navigationBar.bounds.size.width, height);
}
我有2个截图来说明我的问题。
启动应用时导航栏的外观如何: http://cl.ly/image/473B0v0h143t
按下主页按钮然后返回后导航栏的外观如下: http://cl.ly/image/2n012k190r12
非常感谢任何帮助!
答案 0 :(得分:2)
我能解决这个问题的唯一方法(并且我并不为这个问题而感到骄傲,但实际上无法解决它)是在应用程序变为活动状态时触发通知,然后重置ui延迟0.1后出现(是的,直接调用方法不起作用)。
代码是:
- (void) setupAppearanceDelayed {
[self performSelector:@selector(configureForAssetNavigation) withObject:nil afterDelay:0.1];
[self performSelector:@selector(setupAppearance) withObject:nil afterDelay:0.1];
}
- (void) setupAppearance {
[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x2a2a2a)];
[[UINavigationBar appearance] setTintColor:kColours_navBarLabelColour];
[[UINavigationBar appearance] setTitleTextAttributes:[self getTitleTextAttributes]];
if([UIApplication isPad]) {
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:-4 forBarMetrics:UIBarMetricsDefault];
}
else {
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:+3 forBarMetrics:UIBarMetricsDefault];
}
self.navigationBar.tintColor =UIColorFromRGB(0x2a2a2a);
self.navigationBar.translucent = NO;
}
如果有人有更好的解决方案,我很乐意听到它,因为这看起来有点像黑客