AddObserver for device orientation with tab bar controller

286 views Asked by At

I have got 5 tabs bar, all tabs bar come with navigation controller on it except for 3rd tab bar, there is a custom view to make it same as navigation controller bar. Inside of the custom has textfield and button. So I was trying to make the same behaviour with other tab bars with navigation bar. Then, I linked the height and top constraint for textfield and button so it will be able to change based on device orientation.

So I tried to NotificationCenter.default.addObserver(self, selector: #selector(rotated), name: NSNotification.Name.UIApplicationDidChangeStatusBarOrientation , object: nil) in viewWillAppear, it is working like usual. However, if I started to change to landscape mode at first tab. then I changed to third tab, the custom view doesn't change at all.

Another approach: NotificationCenter.default.addObserver(self, selector: #selector(rotated), name: NSNotification.Name.UIApplicationDidChangeStatusBarOrientation , object: nil) in tab bar didSelect, it is still the same issue as stated above, it doesn't work when u entered as landscape mode to change tab from first to third, the custom view still doesn't change at all. but it is working when you change the orientation to portrait then landscape again.

May I know how to solve this problem?

0

There are 0 answers