0

对不起,如果这个问题是重复的,但我找不到相同的解决方案。在 iOS6 中,如果我想为一个 UIViewController 设置默认方向,我只需使用:

- (BOOL)shouldAutorotate {
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscapeLeft;
}

但是如何在 iOS5 中做同样的事情,我测试了两个:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);//not default
}
and
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return (toInterfaceOrientation == UIInterfaceOrientationMaskLandscapeLeft);// = return NO;
}

但默认方向总是纵向。有什么建议吗?

4

4 回答 4

3

调用下面的方法来检查orientation.happy编码的状态:-)

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

- (void) CheckForViewForOrientation:(UIInterfaceOrientation)orientation
{
    if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        //Ur lable portrait view
    }
    else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
    {
        //Ur lable for landscape view
    }
}
于 2013-01-25T07:19:55.893 回答
1

如果您想为整个应用程序实现这一点,请在 app.plist 文件中更改支持的方向 UISupportedInterfaceOrientations

于 2013-01-25T07:14:37.923 回答
1
- (BOOL)shouldAutorotate {

UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];

if (orientation==UIInterfaceOrientationPortrait) {
 // do some 

}

return YES;
}

包括支持 5 和 6 的两种方法

于 2013-01-25T07:20:24.577 回答
1

您需要提供

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
     UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

对于那个单一的视图控制器。

于 2013-01-25T07:27:36.307 回答