Manually set interface orientation

微笑、不失礼 提交于 2019-12-18 04:24:13

问题


Is there any easy way to manually set the 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.


回答1:


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];
    }
}



回答2:


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.




回答3:


override this to control the orientation until loading...

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation


来源:https://stackoverflow.com/questions/7263985/manually-set-interface-orientation

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