popAControllerAnimated上没有调用willAnimateRotationToInterfaceOrientation [英] willAnimateRotationToInterfaceOrientation not called on popViewControllerAnimated

查看:184
本文介绍了popAControllerAnimated上没有调用willAnimateRotationToInterfaceOrientation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MainViewController中,我必须在方向更改时调整一些图像。简单 - 只需将代码添加到 willAnimateRotationToInterfaceOrientation:回调

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

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {
  NSLog(@"orientation: %@", name(orientation));
  ..

按预期工作。在Portrait中,我将另一个方向感知UIViewController推送到UINavigationController上。我旋转到Landscape,一切都很好。

Works as expected. While in Portrait I push another orientation aware UIViewController onto the UINavigationController. I rotate to Landscape and all is good.

然后我通过调用

[self.navigationController popViewControllerAnimated:YES];

当MainViewController的子视图根据autoresize蒙版调整为Landscape时, willAnimateRotationToInterfaceOrientation: 没有被调用!

While the subviews of the MainViewController get adjusted to Landscape according to the autoresize masks, willAnimateRotationToInterfaceOrientation: does not get called!

我希望 willAnimateRotationToInterfaceOrientation:也可以在不在导航控制器堆栈顶部时调用或者至少在返回到堆栈顶部时被调用。

I would have expected willAnimateRotationToInterfaceOrientation: to be either also called when not on top of navigation controller stack or at least get called when returning to the top of the stack.

我假设我可以在流行之前手动调用 willAnimateRotationToInterfaceOrientation:但是感觉错误。

I assume I could manually call willAnimateRotationToInterfaceOrientation: before the pop but that feels wrong.

我缺少什么?

推荐答案

这是预期的我看到的行为。如果UIVC不在堆栈顶部,则不应调用willAnimateRotationToInterfaceOrientation,因为此时没有动画旋转。我在我正在处理的应用程序中处理此问题的方式与上面的海报类似。任何支持所有方向的UIVC都会获得一个新方法

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];
}

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

此外,如果您担心代码在实际不需要时运行,您可以通过viewDidDisappear中设置的实例变量将新UIVC推送到堆栈时跟踪设备的方向并咨询它决定你是否想要做那些东西

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"

这篇关于popAControllerAnimated上没有调用willAnimateRotationToInterfaceOrientation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆