Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITabbar height and display in iPhone not changing dynamically when rotating from landscape to portrait and vice versa iOS11

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

like image 848
eracube Avatar asked Sep 21 '17 16:09

eracube


2 Answers

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.

like image 64
Becca Royal-Gordon Avatar answered Oct 20 '22 01:10

Becca Royal-Gordon


This worked for me on iOS 11.3.1

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    tabBar.invalidateIntrinsicContentSize()
}
like image 21
Haroldo Gondim Avatar answered Oct 20 '22 00:10

Haroldo Gondim