方向改变,我的所有视图控制器什么时候旋转?

发布于 2024-12-03 18:29:01 字数 395 浏览 4 评论 0原文

如果我有多个 UIViewController 被推送到我的导航堆栈上,那么如何/何时重新布局不可见(底部)视图控制器?它们是与可见视图控制器同时布局,还是仅在弹出到显示堆栈时布局?

编辑: 我目前自己管理调整子视图的大小(而不是设置 autoresizing=YES)。我在 willAnimateRotationToInterfaceOrientation 方法中调整大小,以便它的动画效果很好。我猜想任何不在显示堆栈顶部的 uiviewcontroller 都不会调用此方法。那么有没有一种内置方法可以知道当前的 uiviewcontroller 是否是正在显示的,如果不是,我应该重写哪个方法来重新布局不在显示堆栈顶部的 uiviewcontroller 的子视图?

谢谢!

阳光明媚

If I have several UIViewControllers pushed onto my navigation stack, how/when are the none-visible (bottom) view controllers re-layed-out? Do they all get layed-out at the same time as the visible view controller, or only once they are popped onto the display stack?

edit:
I currently manage resizing subviews myself (rather than setting autoresizing=YES). I do my resizing in the willAnimateRotationToInterfaceOrientation method, so that it is all animated nicely. I'm guessing this method doesn't get called for any uiviewcontroller not on top of the display stack. So is there a built-in way to know if the current uiviewcontroller is the one being displayed, and if it isn't, which method should I override to relayout my subviews for the uiviewcontrollers that aren't at the top of the display stack?

Thanks!

Sunny

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘦怹 2024-12-10 18:29:01

我建议检查 viewWillAppear 中的方向。如果您在此处检查方向,则可以放心,视图将始终以给定方向的正确布局显示。不过,您仍然需要在 willAnimateRotationToInterfaceOrientation 中旋转它。

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
    {
        [self layoutForPortrait];    
    }

    else if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
    {
        [self layoutForLandscape];                
    }
}

I would suggest checking the orientation in viewWillAppear. If you check the orientation here, you can be assured that a view will always appear with the correct layout for a given orientation. You still need to rotate it in willAnimateRotationToInterfaceOrientation though.

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
    {
        [self layoutForPortrait];    
    }

    else if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
    {
        [self layoutForLandscape];                
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文