简体   繁体   中英

iOS 7 - Restrict landscape orientation only in one view controller

I need to open the first view controller only in portrait mode. As the rest view controllers will use both orientation. So i have added both orientation in plist file.

-(BOOL) shouldAutorotate {
    //Never called
}

- (NSUInteger) supportedInterfaceOrientations {
    //Never called
}

can any one tell me how to restrict

Fixed it simply by creating UINavigationController class and overriding

-(NSUInteger)supportedInterfaceOrientations
{
    AppDelegate *appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
    if(appDelegate.isOrientationOn) {
        return UIInterfaceOrientationMaskAll;
    }
    return UIInterfaceOrientationMaskPortrait;
}

Use this custom navigation controller class in root window and that's all.

This will lock your View Controller's Orientation in Portrait Mode:

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM