I'm trying to get the toolbar in the bottom of my app to resize when I rotate the iphone/ipod. The navigation controller automatically resizes the navigationbar in iOS8. It does get the right height IF it already is in landscape when the activity is started.
Same size as portrait after it has been rotated to landscape
Smaller because the activity was started in landscape
The toolbar was added in the storyboard.
@IBOutlet var toolbar: UIToolbar!
I have tried to change the rect of the toolbar in the willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval)
Like this:
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
})
}
I also tried without the animation, but no luck.
It does however work if I do the same in didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation)
but without the animation it looks awful because there is some delay.
Solution
from gabbler
- I selected
w Any h Compact
for all iphones (I don't want it smaller on ipads) - Selected my toolbar
- Set the height to 32px on the constraints and Update frames to Items of New Constraint