[英]auto resize height of UIToolbar in landscape orientation
我有一个自定义UIToolBar,当我旋转到横向模式时,该工具不会调整其高度以匹配屏幕顶部的导航栏。 高度保持不变,这使它看起来有些不可思议。 当旋转到横向时,UINavigationController的默认工具栏实际上减小了尺寸(不幸的是,由于推送/弹出转换问题,我无法使用它)。 当前调整大小的掩码是:
[ customToolbar setAutoresizingMask: ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin ) ];
如果添加“ UIViewAutoresizingFlexible Height ”,则会发生奇怪的事情……所以我不确定是否应该使用它。
如果有人知道自动调整大小/旋转UIToolBar以匹配导航栏高度的正确方法,请告诉我。
如果您需要使用与标准导航栏相同的纵横比来调整自定义工具栏的大小,则应实现willAnimateRotationToInterfaceOrientation控制器方法,如下所示:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
CGRect navigationToolbarFrame = self.navigationController.navigationBar.frame;
CGRect customToolbarFrame = CGRectOffset(navigationToolbarFrame, 0.0, navigationToolbarFrame.size.height);
[UIView animateWithDuration:duration animations:^{
self.customToolbar.frame = customToolbarFrame;
}];
}
实现此目的最简单的方法是创建一个UINavigationcontroller
并将其显示为模式视图,我使用如下代码:
NewViewController *f = [[NewViewController alloc]initWithNibName:@"NewView"
bundle:[NSBundle mainBundle]];
self.newViewController = f;
[f release];
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:self.newViewController];
[self presentModalViewController:navigationController animated:YES];
由于将视图显示为导航控制器,因此可以使用工具栏属性。
不确定遮罩,但是您可以在-willRotateToInterfaceOrientation:duration:中调整视图的大小。 只需在那里更改框架即可满足您的需求。 您也可以在-willAnimateRotationToInterfaceOrientation:duration中执行此操作:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.