如何启用/禁用方向(旋转)直到按UIBarButtonItem?

Pau*_*ues 2 iphone rotation orientation ios

我在TabBarController中有一个带有3个选项卡的应用程序.在第一个选项卡上,当用户按下NavigationBar上的按钮时,可以启用从纵向到横向的旋转?用户第一次无法旋转,只有当他按下按钮时.

我正在使用SDK iOS 6.

提前致谢!

jjv*_*360 6

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    // Return YES for supported orientations
    return allowedToRotate;

}
Run Code Online (Sandbox Code Playgroud)

然后BOOL allowedToRotate;在您的类标题中有一个,并在您想要允许旋转时将其设置为YES.如果您使用的是iOS 6:

-(NSUInteger)supportedInterfaceOrientations {

    if (allowedToRotate)
        return UIInterfaceOrientationMaskAll;
    else
        return UIInterfaceOrientationMaskPortrait;

}
Run Code Online (Sandbox Code Playgroud)

这应该有用,虽然我还没试过......