Interface orientation in iOS 6.0

前端 未结 5 1387
[愿得一人]
[愿得一人] 2020-12-01 05:19

How to use the following methods to support interface orientation in iOS 6.0:

shouldAutorotate

supportedInterfaceOrientations

preferredInterfaceOrientation         


        
5条回答
  •  隐瞒了意图╮
    2020-12-01 06:16

    My app has an instance of a custom UINavigationController subclass, that presents several view controllers, all in portrait only, except when playing a video, in which case I want to additionally allow both landscape orientations.

    Based on @uerceg 's answer, this is my code.

    First, I enabled Portrait, Landscape Left and Landscape right in Xcode -> Target -> Summary.

    In the UINavigationController subclass's implementation, I #import'ed .

    Then I implemented these methods:

    // Autorotation (iOS <= 5.x)
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        if ([self modalViewController] && [[self modalViewController] isKindOfClass:[MPMoviePlayerController class]]) {
    
            // Playing Video: Anything but 'Portrait (Upside down)' is OK
            return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
        }
        else{
            // NOT Playing Video: Only 'Portrait' is OK
            return (interfaceOrientation == UIInterfaceOrientationPortrait);
        }
    }
    
    
    // Autorotation (iOS >= 6.0)
    
    - (BOOL) shouldAutorotate
    {
        return YES;
    }
    
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        NSUInteger orientations = UIInterfaceOrientationMaskPortrait;
    
        if ([self modalViewController] && [[self modalViewController] isKindOfClass:[MPMoviePlayerController class]]) {
    
            // Playing Video, additionally allow both landscape orientations:
    
            orientations |= UIInterfaceOrientationMaskLandscapeLeft;
            orientations |= UIInterfaceOrientationMaskLandscapeRight;
    
        }
    
        return orientations;
    }
    

提交回复
热议问题