what method will called when we start to rotate device and after it finished

后端 未结 5 741
抹茶落季
抹茶落季 2021-02-01 16:54

i want to detect a rotation process on ipad programmatically. In this case i want to set a boolean into yes, when the rotation will begin, and set it false after the rotation di

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-01 17:13

    All the above methods(in the answer by @Nekto) are deprecated in iOS8.0 and later versions. Source: iOS Developer Library

    As of iOS 8, all rotation-related methods are deprecated. Instead, rotations are treated as a change in the size of the view controller’s view and are therefore reported using the viewWillTransitionToSize:withTransitionCoordinator: method. When the interface orientation changes, UIKit calls this method on the window’s root view controller. That view controller then notifies its child view controllers, propagating the message throughout the view controller hierarchy.

    In iOS8 or later you can use the below method.

    - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id )coordinator
    {
        [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
    
        [coordinator animateAlongsideTransition:^(id context) {
    
            // Stuff you used to do in willRotateToInterfaceOrientation would go here.
            // If you don't need anything special, you can set this block to nil.
    
        } completion:^(id context) {
    
            // Stuff you used to do in didRotateFromInterfaceOrientation would go here.
            // If not needed, set to nil.
    
        }];
    }
    

提交回复
热议问题