0xc*_*ced 15 iphone uitoolbar ios
来自iOS人机界面指南,iOS UI元素使用指南
在iPhone上,考虑设备旋转时工具栏高度的自动更改.特别是,请确保您的自定义工具栏图标非常适合横向显示的细条.不要以编程方式指定工具栏的高度.
我可以看到Mail,Twitter for iPhone和Dropbox的高度从44点变为32点,但是当我添加工具栏(使用Interface Builder)并让我的UIViewController子类自动旋转(shouldAutorotateToInterfaceOrientation:返回YES)时,工具栏会不会在设备旋转时自动更改其高度.
该UIToolbar类参考并没有提到高度的这种自动变化,所以我应该改变它编程,即使HIG说不要指定编程工具栏的高度?
vis*_*kh7 19
您是否检查了工具栏的自动调整大小属性?
0xc*_*ced 15
正如yonel和George在7KV7回答的评论中指出的那样,更改自动调整遮罩在iOS 5上无法正常工作.
我通过使用- [UIView sizeThatFits:]方法找到了另一种解决方案.我是这样做的:
- (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))};
}
Run Code Online (Sandbox Code Playgroud)
然后我layoutForInterfaceOrientation:在视图控制器viewWillAppear:和willAnimateRotationToInterfaceOrientation:duration:方法中调用此方法.
尽管如此,高度仍以编程方式更改,但至少该值不是硬编码的.
Bri*_*kel 12
使用自动布局实现此行为要简单得多.我只在iOS8中进行过测试,但以下代码适用于方向更改所需的动画:
public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
toolbar.invalidateIntrinsicContentSize()
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13789 次 |
| 最近记录: |