Orientation in a UIView added to a UIWindow

后端 未结 6 1883
眼角桃花
眼角桃花 2020-11-28 01:21

I have a UIView which is supposed to cover the whole device (UIWindow) to support an image zoom in/out effect I\'m doing using core animation where a user taps a button on a

6条回答
  •  孤街浪徒
    2020-11-28 02:00

    Another solution how I solved this problem.

    Define the current Orientation:

    @interface AJImageCollectionViewController (){
        UIInterfaceOrientation _currentOrientation;
    }
    @end
    

    Then check the orientation in the viewWillLayoutSubviews:

    - (void)viewWillLayoutSubviews {
        [self checkIfOrientationChanged];
    }
    
    - (void)checkIfOrientationChanged {
        UIInterfaceOrientation newOrientation = [[UIApplication sharedApplication] statusBarOrientation];
        BOOL newOrientationIsPortrait = UIInterfaceOrientationIsPortrait(newOrientation);
        BOOL oldOrientationIsPortrait = UIInterfaceOrientationIsPortrait(_currentOrientation);
    
        // Check if the orientation is the same as the current
        if(newOrientationIsPortrait != oldOrientationIsPortrait){
            _currentOrientation = newOrientation;
            // Do some stuff with the new orientation
        }
    }
    

提交回复
热议问题