How to get default LandscapeLeft Orientation in iOS5?

可紊 提交于 2019-12-31 04:41:26

问题


Sorry if this question is duplicate, but I can't find the same solution. In iOS6, if I want to set default orientation for one UIViewController, I just use:

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

But how to do same in iOS5, I test both:

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

But the default orientation always Portrait.Any suggestion?


回答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
    }
}



回答2:


If you want to achieve this for whole application, change supported orientation UISupportedInterfaceOrientations in app.plist file




回答3:


- (BOOL)shouldAutorotate {

UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];

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

}

return YES;
}

Include both the methods to support both 5 and 6




回答4:


You need to provide

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

for that single View controller.



来源:https://stackoverflow.com/questions/14516992/how-to-get-default-landscapeleft-orientation-in-ios5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!