0

I have 2 screens: the first screen support all orientations, the 2nd screen just support landscape right orientation.
I want the first screen to save its orientation before pushing to the second screen and return to that orientation when it pops back from the second screen.

my code:

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[UIDevice currentDevice] setValue:@(currentOrientaion) forKey:@"orientation"];
    [UIViewController attemptRotationToDeviceOrientation];
}

it's work but sometime screen rotates many time to change orientation.
Someone help me: why is that?

Nguyen Hoan
  • 1,583
  • 1
  • 11
  • 18
  • Please try changing the following Target --> General and set Orientation Mode to Portrait only and Go To Target --> General and enable Requires fullscreen, I've followed [this](https://stackoverflow.com/questions/28938660/how-to-lock-orientation-of-one-view-controller-to-portrait-mode-only-in-swift) with above-mentioned settings to lock the orientation properly . – Sayooj Dec 17 '19 at 09:03
  • Try this might help your problem.https://stackoverflow.com/questions/634745/how-to-programmatically-determine-iphone-interface-orientation – Nicol Vishan Dec 17 '19 at 09:03
  • also this one https://stackoverflow.com/questions/25666269/how-to-detect-orientation-change – Russell Dec 17 '19 at 09:04

1 Answers1

-1

You should call these lines in some other method like ViewDidLoad because for a specific view controller, viewWillAppear method may call multiple times.

iGatiTech
  • 2,306
  • 1
  • 21
  • 45
Gaurav Malik
  • 1,220
  • 1
  • 7
  • 3