Why is viewWillTransitionToSize called when power button or home button press?

Hi Team,


I am seeing that if we press power button(lock device) or home button(minimise app) , viewWillTransitionToSize function calles that time.

Previous functions willRotateToInterfaceOrientation not call at this time, please guide me

I'd like to add my voice to this question. It also happens when a user does some action in my app that causes the app to go into the background, for example if they tap on a link that takes them to the Safari app. I've tested on iOS 10.


Here is the world's simpliest test class that demonstrates the strange behavior:

{
    override open func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
        switch (UIApplication.shared.applicationState) {
        case .active:
            print("Application State: Active")
        case .background:
            print("Application State: Background")
        case .inactive:
            print("Application State: INActive")
        }
    }
}


When its being called the app is already in the Background state! And its actually being called twice - with different sizes, ending up with the original size!


This behavior has a very undesirable in many cases displaying the last cells of a UITableView - the contentOffset is adjusted which leaves the user with a bad experience when they come back into the app -- its not displaying exactly the same thing as whence they left.

I'm not at all sure why this is happening, but it was affecting us as well. As a work around, before making any UI adjustments, I check to see if we're active


[UIApplication sharedApplication].applicationState != UIApplicationStateBackground


and if we're not active, I don't make 'em. Seems to fix our problem. Good luck!


Ben

Why is viewWillTransitionToSize called when power button or home button press?
 
 
Q