I was adding UITabBar without using AutoLayout and it was working fine until iOS 10.3.1. There seems to be a new feature in iOS 11 which is that the height of UITabBar is 49 in portrait and 32 in landscape mode (Photo App is a good example). Now when I run my app built in iOS11, if I start my app in landscape mode the height of UITabBar starts with the height of 32 but when it is rotated to portrait mode it stays in 32 and the icons get bigger and edge out of the TabBar frame. When I start my app in portrait mode, the height of TabBar starts with the height of 49 and stays the same when rotated to portrait mode (which is acceptable).
I tried to fix the issue using AutoLayout and constraints, however I am not able to solve it. If anyone is having this issue, it would be a great help.
This problem seems to be occurring only in iPhone non plus devices.
Update: The height is fixed by using the answer below, but in the landscape mode the text and the icon of UITabBar item are not aligned horizontally but instead vertically in iPhone X.
The problem I am facing is similar to the question here
I had this problem and solved it by calling invalidateIntrinsicContentSize()
on the tab bar, then updateConstraintsIfNeeded()
on a superview of it. In my case, I called both inside an animation block, but it may be possible to move one or both of them out of it.
This worked for me on iOS 11.3.1
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
tabBar.invalidateIntrinsicContentSize()
}
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