Iphone中的定位问题

时间:2010-11-15 07:26:22

标签: iphone objective-c cocoa-touch orientation

大家好 我正在实现一个使用TabBar和Navigation Controller的应用程序。在这个应用程序中,我需要更改特定视图的方向(我的应用程序中的照片库视图)(想要实现方向功能)。我在所有视图控制器的shouldautoroateorientation中设置了布尔值YES。通过这样做,所有视图都是旋转的。我只想旋转一个特定的视图。任何人都有这个想法请回复。

提前致谢.... :)

3 个答案:

答案 0 :(得分:1)

唯一应该为shouldAutoRotateOrientation返回“YES”的视图是那些实际想要旋转的视图。请注意,这意味着,有时导航和标签栏控制器将返回YES,有时它们应返回NO。

我实际上没有试过这个,但是把它设置好看看会发生什么......

答案 1 :(得分:1)

我从一个新的Tab Bar应用程序开始,然后创建一个类“MyTabBarController”(派生自UITabBarController)并将MainWindow.xib更改为使用MyTabBarController而不是UITabBarController。然后我将以下代码添加到MyTabBarController:

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
    BOOL result = interfaceOrientation == UIInterfaceOrientationPortrait;
    if (self.selectedIndex == 0)
        result = YES;
    return result;
}

一旦我这样做,只有第一个视图控制器会旋转,第二个视图控制器不会旋转。

但是,我注意到此方法仅在设备实际旋转时调用,一旦处于横向状态,点击另一个选项卡将在横向上显示该方法。所以也许你想做的事情不能完全做到。

答案 2 :(得分:0)

您是否正在评估shouldAutorotateOrientation中的方向?如果您要定位手机,则您希望在

上允许轮换的视图中,您的实现应如下所示
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

这在所有其他观点中

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
相关问题