user1105951
user1105951

Reputation: 2287

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)

Upvotes: 0

Views: 825

Answers (1)

Boudhayan
Boudhayan

Reputation: 760

- (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.

Upvotes: 0

Related Questions