【发布时间】:2011-01-08 14:56:07
【问题描述】:
我的导航控制器的导航栏在旋转到横向时不会改变高度。
看到它保持在 44 像素,而不是我认为的 34 像素。
我该怎么做才能解决这个问题?
【问题讨论】:
标签: iphone uinavigationcontroller uinavigationbar landscape
我的导航控制器的导航栏在旋转到横向时不会改变高度。
看到它保持在 44 像素,而不是我认为的 34 像素。
我该怎么做才能解决这个问题?
【问题讨论】:
标签: iphone uinavigationcontroller uinavigationbar landscape
您必须将导航控制器作为子视图直接添加到窗口中,否则这不会自动工作。 (无需手动更改导航栏的框架。)
AppDelegate 的 -[application:didFinishLaunchingWithOptions:] 方法应包含类似
[window addSubview:self.yourNavController.view];
要获得自动运行的示例,您还可以在 XCode 中创建一个新的基于导航的应用程序,并为始终返回 YES 的 RootViewController 的 shouldAutorotateToInterfaceOrientation: 方法添加一个实现。
【讨论】:
在你的类的 autoRotation 方法中,像这样改变你的 navBar 的框架:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if((self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight))
{
self.navigationController.navigationBar.frame = CGRectMake(0,0,480,32);
}
else if((self.interfaceOrientation == UIInterfaceOrientationPortrait) || (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))
{
self.navigationController.navigationBar.frame = CGRectMake(0,0,320,44);
}
else
{
assert(false);
}
}
【讨论】: