willAnimateRotationToInterfaceOrientation not called on popViewControllerAnimated

后端 未结 5 1531
遇见更好的自我
遇见更好的自我 2020-12-14 12:08

In the MainViewController I have to adjust some images on orientation change. Easy - just add the code to the willAnimateRotationToInterfaceOrientation: callback

5条回答
  •  感情败类
    2020-12-14 13:04

    This is expected behavior as I see it. If the UIVC is not on the top of the stack, then willAnimateRotationToInterfaceOrientation shouldn't be called as no rotation is being animated at that time. The way I've been handling this in the app I am working on now is similar to the above poster. Any UIVC that supports all orientations gets a new method

    - (void) updateLayoutForNewOrientation: (UIInterfaceOrientation) orientation;

    This method is called from two places:

    
    -(void) viewWillAppear: (BOOL) animated {
      [super viewWillAppear: animated];
      [self updateLayoutForNewOrientation: self.interfaceOrientation];
    }

    -(void) willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation duration: (NSTimeInterval) duration { [self updateLayoutForNewOrientation: interfaceOrientation]; }

    The new method is simple:

    
    - (void) updateLayoutForNewOrientation: (UIInterfaceOrientation) orientation {
        if (UIInterfaceOrientationIsLandscape(orientation)) {
            // Do some stuff
        } else {
            // Do some other stuff
        }
    }
    

    Additionally, if you were worried about the code running when its not actually needed, you could track the orientation the device was in when the new UIVC was pushed on to the stack via an instance variable set in viewDidDisappear and consult it to decide if you want to "Do the stuff"

提交回复
热议问题