开发者

Manually set interface orientation

开发者 https://www.devze.com 2023-03-31 22:49 出处:网络
Is there any easy way to manually set t开发者_运维技巧he orientation of an interface?I need to set the interface to portrait even though the device orientation might be in landscape during loading.Kin

Is there any easy way to manually set t开发者_运维技巧he orientation of an interface? I need to set the interface to portrait even though the device orientation might be in landscape during loading. Kinda want to stay away from CGAffineTransforms.


One method I know that works for me (and is a bit of a hack and can display one orientation before changing to the orientation you want) is:

- (void)viewDidAppear:(BOOL)animated 
{
    [super viewDidAppear:animated];

    UIApplication* application = [UIApplication sharedApplication];

    if (application.statusBarOrientation != UIInterfaceOrientationPortrait)
    {
        UIViewController *c = [[UIViewController alloc]init];
        [self presentModalViewController:c animated:NO];
        [self dismissModalViewControllerAnimated:NO];
        [c release];
    }
}


First, set your app and views to only support portrait, then use this category method taken from my refactoring library, es_ios_utils:

@interface UIViewController(ESUtils)
    // Forces without using a private api.
    -(void)forcePortrait;
@end

@implementation UIViewController(ESUtils)

-(void)forcePortrait
{
    //force portrait orientation without private methods.
    UIViewController *c = [[UIViewController alloc] init];
    [self presentModalViewController:c animated:NO];
    [self dismissModalViewControllerAnimated:NO];
    [c release];
}

@end

The view, dismissed before the frame completes, won't be displayed.


override this to control the orientation until loading...

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
0

精彩评论

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