设备旋转时的UIToolbar高度 [英] UIToolbar height on device rotation

查看:108
本文介绍了设备旋转时的UIToolbar高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从iOS人机界面指南 iOS UI元素使用指南

From the iOS Human Interface Guidelines, iOS UI Element Usage Guidelines


在iPhone上,考虑设备轮换时出现的
工具栏高度
的自动更改
。特别是
,请确保您的自定义
工具栏图标非常适合以横向
方向显示的较薄的
栏。不要以编程方式指定工具栏的高度

On iPhone, take into account the automatic change in toolbar height that occurs on device rotation. In particular, make sure your custom toolbar icons fit well in the thinner bar that appears in landscape orientation. Don’t specify the height of a toolbar programmatically.

我可以看到高度从44点变为32点例如,在 Mail Twitter for iPhone Dropbox 中,但是当我添加工具栏(使用Interface Builder)并让我的UIViewController子类自动生成时rotate( shouldAutorotateToInterfaceOrientation:返回YES),工具栏不会在设备旋转时自动更改其高度。

I can see the height changing from 44 points to 32 points in Mail, Twitter for iPhone and Dropbox for example, but when I add a toolbar (with Interface Builder) and have my UIViewController subclass to automatically rotate (shouldAutorotateToInterfaceOrientation: returns YES), the toolbar does not automatically change its height on device rotation.

< a href =http://developer.apple.com/library/ios/#documentation/uikit/reference/UIToolbar_Class/Reference/Reference.html\"rel =noreferrer> UIToolbar类参考没有提到这个自动更改高度,所以我应该以编程方式更改它,即使HIG说不以编程方式指定工具栏的高度

The UIToolbar Class Reference does not mention this automatic change of height, so am I supposed to change it programmatically even though the HIG says Don’t specify the height of a toolbar programmatically?

推荐答案

正如 yonel George 中指出的那样来自 7KV7 的答案,更改自动调整屏幕在iOS 5上无法正常工作。

As noted by yonel and George in the comments from 7KV7 answer, changing the autoresizing mask does not work as intended on iOS 5.

我使用 - [UIView sizeThatFits: ] 方法。我是这样做的:

I found another solution by using the -[UIView sizeThatFits:] method. Here is how I did it:

- (void) layoutForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Adjust the toolbar height depending on the screen orientation
    CGSize toolbarSize = [self.toolbar sizeThatFits:self.view.bounds.size];
    self.toolbar.frame = (CGRect){CGPointMake(0.f, CGRectGetHeight(self.view.bounds) - toolbarSize.height), toolbarSize};
    self.webView.frame = (CGRect){CGPointZero, CGSizeMake(CGRectGetWidth(self.view.bounds), CGRectGetMinY(self.toolbar.frame))};
}

然后我称之为 layoutForInterfaceOrientation:方法 viewWillAppear: willAnimateRotationToInterfaceOrientation:duration: methods。

Then I call this layoutForInterfaceOrientation: method in my view controller viewWillAppear: and willAnimateRotationToInterfaceOrientation:duration: methods.

尽管如此,高度仍以编程方式更改,但至少该值未进行硬编码。

The height is nonetheless changed programmatically but at least the value is not hardcoded.

这篇关于设备旋转时的UIToolbar高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆