Swift - how to fix in Landscapeleft a screen?

Asked

Viewed 51 times

1

The app has 4 screens and, only one should be fixed in Landscapeleft. The others are in Portrait..

On the tab General I set it up this way.

General:

inserir a descrição da imagem aqui

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;
}

1 answer

1


Cristian,

In the viewDidLoad() method put:

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

And overwrite:

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

So that the screen does not return to portrait, for example, overwrite the method shouldAutorotate(), returning false.

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

I hope I helped. I don’t know if there is a more intelligent and automatic way.

  • This way he goes to Lalscape, but he doesn’t stop me from going back to Portrait.

  • 1

    What if you overwrite the shouldAutorotate? example: override func shouldAutorotate() -> Bool { Return false }

  • I was already doing it, now it worked! Thank you.

  • @Cristiancotrena cool! I edited the question adding the shouldAutorotate.

  • I had to override value by mode to work :)

  • 1

    @Cristiancotrena I saw :-) sorry, it was like "value" and replaced by mode at the time of reply and forgot to put in the line below ;-P thanks for the edition!

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.