简体   繁体   中英

viewWillTransitionToSize and orientation

If I add property to UIViewController "myisLandscape" (BOOL) and I update this property everytime viewWillTransitionToSize is called

-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{     
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];

    // will execute before rotation
    [coordinator animateAlongsideTransition:^(id  _Nonnull context) {

        self.myIsLandscape = (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]));

    } completion:^(id  _Nonnull context) {

        // will execute after rotation

    }];

}

beside this method, is there other method I need to update self.myIsLandscape so it will always be with correct value ?

I need this property to access to check current orientation of UIViewController from background thread ( I don't want to use dispatch)

- (void)viewWillTransitionToSize:(CGSize)size 
       withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator

This method is a part of UIContentContainer Protocol. This protocol defines methods to redesign the contents of your view controller according to the size changes. When you implement the below above method, it notifies the View Controller that it's view size is about to change.

So the check that you are doing, will return the correct value always. No need to worry.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM