如何获得默认LandscapeLeft取向的iOS5?(How to get default Lan

2019-08-08 05:23发布

很抱歉,如果这个问题是重复的,但我不能找到同样的解决方案。 在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;
}

但是默认的方向总是Portrait.Any建议吗?

Answer 1:

call the below method where you want to check the status of orientation.happy coding :-)

- (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
    }
}


Answer 2:

如果要达到这一目的的整个应用程序,支持改变方向UISupportedInterfaceOrientations在app.plist文件



Answer 3:

- (BOOL)shouldAutorotate {

UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];

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

}

return YES;
}

包括同时支持5和6的方法



Answer 4:

您需要提供

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

对于单一视图控制器。



文章来源: How to get default LandscapeLeft Orientation in iOS5?