开发者

How to disable any autorotation?

I am trying to code for calling Landscape screen from Portrait screen. When current screen orientation is Landscape, it would be doesn't allow any autorotation.

I've tried the following code :

// Override to allow orientations other than the default portrait orientation.
/*- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}*/

- (void)viewDidLoad {

   [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationL开发者_StackOverflow社区andscapeRight;
   CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
   landscapeTransform = CGAffineTransformTranslate(landscapeTransform, +90.0, +90.0);
   [self.view setTransform:landscapeTransform];
}

But above code is allowing UIInterfaceOrientationLandscapeRight.

How to disable any autorotation ?

Thanks in advance.


Do you want start your application in the landscape mode or not? In all case you must override the shouldAutorotateToInterfaceOrientation method.

But if you want start your application in the Portrait mode and then go to the Landscape mode you can add a static boolean to know if you must stay in the landspace mode or not. You code must look something like that:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if(isInPortraitMode) {
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    } else {
        if(interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
            isInPortraitMode  = YES;
        }
        return YES;
    }
}

- (void)viewDidLoad {
    isInPortraitMode = NO;
    //...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜