Swift - how to set LandscapeLeft a screen?

1

The app has 4 screens being that, only one should stay fixed in LandscapeLeft. The others are in Portrait ..

In the General tab I have set this up.

General:

In Objective-C I can force this way:

Solution in Objective-C:

.h

-(NSUInteger) supportedInterfaceOrientations;

.m

- (void)viewDidLoad {
    [super viewDidLoad];
    self.supportedInterfaceOrientations;
}

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscapeLeft;
}
    
asked by anonymous 08.06.2016 / 16:29

1 answer

1

Cristian,

In the viewDidLoad () method, place:

let mode = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(mode, forKey: "orientation")

And overwrite:

override func shouldAutorotate() -> Bool {
    return true
}

For the canvas to not return to portrait, for example, overwrite the shouldAutorotate () method, returning false.

override func shouldAutorotate() -> Bool {
    return false
}

I hope I have helped. I do not know if there is a more intelligent and automatic way.

    
08.06.2016 / 18:34