xcode - How do I keep views locked into portrait mode, but still allow one view to rotate?

后端 未结 3 1593
遇见更好的自我
遇见更好的自我 2021-01-01 05:59

I\'m having a problem with device rotation. Except for ONE view, where I show a company splash screen, I want to lock all the remaining app views into Portrait display. In

相关标签:
3条回答
  • 2021-01-01 06:07

    Slap this method into the view controller you want locked in a certain orientation.

    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskLandscape;
    }
    

    just change to the orientation you want (the above locks it in landscape)

    0 讨论(0)
  • maybe u should allow all orientations, and lock portrait orientation in each class except company splash with

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        if (interfaceOrientation == UIInterfaceOrientationPortrait) {
        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
        } else {
        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
        }
    }
    
    0 讨论(0)
  • 2021-01-01 06:28

    Add an observer to the viewDidLoad method of the view you want to rotate like this :

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter]
     addObserver:self selector:@selector(orientationChanged:)
     name:UIDeviceOrientationDidChangeNotification
     object:[UIDevice currentDevice]];
    

    and then set the views according the the landscape view inside the orientationChanged method like this :

    - (void) orientationChanged:(NSNotification *)note{
    UIDevice * device = [UIDevice currentDevice];
    switch(device.orientation)
    {
        case UIDeviceOrientationPortrait:
    
            break;
        case UIDeviceOrientationPortraitUpsideDown:
    
            break;
        case UIDeviceOrientationLandscapeLeft:
    
            break;
        case UIDeviceOrientationLandscapeRight:
    
            break;
    
        default:
            break;
      };
    }
    
    0 讨论(0)
提交回复
热议问题