How to change only one ViewController to landscape

2019-08-31 10:04发布

问题:

I have two view controllers,I have some videos in FirstViewController,if I click on video it will display on SecondViewController with landscape mode,after clicking back button again the FirstViewController should appear in Potrait mode.Here is my code

-(NSUInteger)supportedInterfaceOrientations
 {

     return UIInterfaceOrientationMaskLandscape;
 }

but it not works for me.

Thanks

回答1:

I made a simple workaround at this question a few weeks ago. If you want, you can link the return value of the rootviewcontroller shouldAutoRotate/supportedInterfaceOrientation to the presentation of the second view controller doing this

RootViewController

@property (nonatomic, retain) BOOL autoRotate;
@property (nonatomic, retain) UIInterfaceOrientation interfaceOrientation;

-(void)setAutorate:(BOOL)newValue
{
    _autoRotate = newValue;
}
-(void)setInterfaceOrientation: (UIInterfaceOrientation)newInterface
{
    _interfaceOrientation = newInterface;
}

-(BOOL)shouldAutorotate
{
    return _autoRotate;
}
-(UIInterfaceOrientation)supportedInterfaceOrientation
{
    return _interfaceOrientation;
}

And in the secondView controller you have to call the setter method in the viewDidAppear to modify values. Then, in the viewDidDisappear, or when you dismiss the controller, you will reset the values.