Is there a documented way to set the iPhone orientation?

后端 未结 17 1281
清歌不尽
清歌不尽 2020-11-22 11:09

I have an app where I would like to support device rotation in certain views but other don\'t particularly make sense in Landscape mode, so as I swapping the views out I wou

17条回答
  •  误落风尘
    2020-11-22 11:44

    There is a simple way to programmatically force iPhone to the necessary orientation - using two of already provided answers by kdbdallas, Josh :

    //will rotate status bar
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
    
    
    //will re-rotate view according to statusbar
    UIViewController *c = [[UIViewController alloc]init];
    [self presentModalViewController:c animated:NO];
    [self dismissModalViewControllerAnimated:NO];
    [c release];
    

    works like a charm :)

    EDIT:

    for iOS 6 I need to add this function: (works on modal viewcontroller)

    - (NSUInteger)supportedInterfaceOrientations
    {
        return (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight);
    }
    

提交回复
热议问题