【发布时间】:2014-10-28 12:57:13
【问题描述】:
我试图让我的应用程序底部的工具栏在我旋转 iphone/ipod 时调整大小。导航控制器在 iOS8 中自动调整导航栏的大小。如果在活动开始时它已经处于横向状态,它确实会获得正确的高度。
旋转为横向后与纵向大小相同
较小,因为活动是在横向开始的
工具栏已添加到情节提要中。
@IBOutlet var toolbar: UIToolbar!
我试图改变willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval)中工具栏的矩形
像这样:
override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
var customToolbarFrame: CGRect!
if toInterfaceOrientation == UIInterfaceOrientation.Portrait {
customToolbarFrame = CGRectMake(0,self.view.bounds.size.height - 44, self.toolbar.frame.size.width, 44)
}
else {
customToolbarFrame = CGRectMake(0,self.view.bounds.size.height - 32, self.toolbar.frame.size.width, 32)
}
UIView.animateWithDuration(duration, animations: {
self.toolbar.frame = customToolbarFrame
})
}
我也尝试过不使用动画,但没有运气。
但是,如果我在 didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) 中执行相同的操作,它确实可以工作,但如果没有动画,它看起来很糟糕,因为有一些延迟。
解决方案
来自胡言乱语
- 我为所有 iphone 选择了
w Any h Compact(我不希望它在 ipad 上变小) - 选择了我的工具栏
- 在约束上将高度设置为 32px,并更新帧到新约束项
【问题讨论】: