自动调整UIToolbar的横向高度

Ivo*_*Ivo 2 iphone rotation uitoolbar autoresize

我有一个自定义UIToolBar,当我旋转到横向模式时,它不会调整它的高度以匹配屏幕顶部的导航栏.高度保持不变,这看起来有点奇怪.UINavigationController中的默认工具栏在旋转到横向时实际上减小了尺寸(遗憾的是,由于推/弹转换问题,我无法使用它).当前的大小调整掩码是:

[ customToolbar setAutoresizingMask: ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin ) ];
Run Code Online (Sandbox Code Playgroud)

如果我添加"UIViewAutoresizingFlexible Height "会发生奇怪的事情......所以我不确定是否应该使用它.

如果有人知道自动调整大小/旋转UIToolBar以匹配导航栏高度的正确方法,请告诉我.

vor*_*max 5

如果您需要使用与标准导航栏相同的宽高比调整自定义工具栏的大小,则应实现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;     
    }];
}
Run Code Online (Sandbox Code Playgroud)