【问题标题】:Rotating all the views of a TabBarController旋转 TabBarController 的所有视图
【发布时间】:2010-08-29 19:14:34
【问题描述】:

我有一个有 4 个视图的 TabBarController 应用程序。 我已经在所有 4 个 viewControllers 上设置了 autorotate 方法返回 yes :

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return YES;
}

多亏了这一点,现在当我旋转 iPhone 时,旋转可以正常工作,甚至 TabBar 也会旋转。

在每一个视图中,我都可以使用以下代码更新以查看何时发生旋转:

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [self adjustViewsForOrientation:toInterfaceOrientation];
}

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
    if (orientation == UIInterfaceOrientationLandscapeLeft ||
        orientation == UIInterfaceOrientationLandscapeRight) {

//Here i can update the view when it goes to landscape

    }
    else if (orientation == UIInterfaceOrientationPortrait ||
             orientation == UIInterfaceOrientationPortraitUpsideDown) {

//Here i can update the view when it goes to portrait

    }

}

问题是当我进行旋转时,只有当前显示的视图在更新。如果稍后我单击 tabBar 更改视图,我会看到视图未针对新方向更新。

有没有办法让所有知道方向的视图都改变了?

【问题讨论】:

    标签: iphone


    【解决方案1】:

    好的,我找到了! =D

    诀窍在于使用函数:

    - (void)viewWillAppear:(BOOL)animated 
    

    只需在您的 viewControllers 中调用它,然后插入代码中即可更新视图。享受吧!

    【讨论】:

    • 我必须等到明天再做!
    • 我怀疑这只发生在您已经访问过的视图中,而不会发生在您第一次访问的视图中。
    猜你喜欢
    • 2017-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多