如何根据UINavigation bar的大小设置内容大小
问题描述:
当我的应用程序切换到横向时,我正在调整导航栏的大小。 但我无法根据其高度设置导航栏的内容大小。如何根据UINavigation bar的大小设置内容大小
Landscape image: - 在此图像中,导航栏左上角的条目和标题在切换到横向时不会调整大小...应根据导航栏的高度重新调整大小。
请问我有什么想法吗?
感谢
迪皮卡
答
覆盖的方法:当你的设备方向发生
- (UIView *)rotatingHeaderView
{
return yourNavigationBar;
}
这种方法将被调用。
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(mainLoginView.superview == self.view || modulesView.superview == self.view)
{
return NO;
}
else
{
return YES;
}
}
与您的代码替换此方法并回复我会发生什么:)
答
我做这个委托方法: -
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
if(mainLoginView.superview == self.view || modulesView.superview == self.view){
return NO;
}else{
[self rotateTheNavigation:contactsNavigation withOrientation:interfaceOrientation];
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
}
答
如果必须重新计算你的观点,你” ð最好把你的代码放到
-
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
, - 或
-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
shouldAutorotateToInterfaceOrientation情况应该只是一个回应的问题:“这种观点应该控制旋转或不”。
例如:如果你设置了正确的调整在Interface Builder设置
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
// Get the new screen width
self.cellWidth = self.view.frame.size.width;
// Recalculate the view
[self rebuildTheView];
}
在大多数的情况下,所有的ViewController实施shouldAutorotate就足够了。检查你这样做实现didRotateFromInterfaceOrientation或willAnimateRotationToInterfaceOrientation
例如前:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return [ViewToolkit orientationIsSupported:interfaceOrientation];
}
感谢您的建议。我已经尝试过但它不适用于我。当设备方向发生时,此方法未被调用。 – Deepika 2010-05-20 14:23:06
您在代理shouldAutorotateorientation权利中返回YES? – Manjunath 2010-05-21 04:16:06
我的应用程序中有很多视图和导航控制器。 我想做这件事: - 如果登录视图或模块视图可见,那么限制方向,如果任何导航控制器视图可见,那么我通过转换来旋转该导航视图。然后我根据方向设置导航栏的高度。我可以设置导航栏的高度,但是我无法设置UIBarButtonitem的大小和导航栏的标题。你可以在风景图像中看到它。 – Deepika 2010-05-21 05:41:37