In generally, on the landscape mode, the navigation bar controlled by navigation controller automatically reduce its size smaller.
But I want to prevent that autoresizing.
First, I set the navigation bar hidden and used another navigation bar not controlled by navigation controller. So, I solved the problem. But I want to find the way to disable autoresizing the navigation bar on landscape without using another bar not controlled by navigation controller.
I solved this by creating a category on UINavigationBar:
@implementation UINavigationBar (customHeight)
- (CGSize)sizeThatFits:(CGSize)size
{
CGSize newSize = CGSizeMake(self.frame.size.width,44);
return newSize;
}
@end
With the category created, the height now stays fixed at 44 - I don't even need to import the category anywhere.
My app uses storyboards but I'm pretty sure it would work either way.
This will work for iOS 8
extension UINavigationBar {
public override func sizeThatFits(size: CGSize) -> CGSize {
var newSize = CGSizeMake(UIScreen.mainScreen().bounds.width, 44)
return newSize
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With