I want to set UIViewController in Portrait, I tried to add
- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotate {
return [UIApplication sharedApplication].statusBarOrientation != UIDeviceOrientationPortrait;
}
But when I take my phone in Landscape, then enter this UIViewController,
I will run into Landscape first, then rotate to portrait!
but I don't want it shows landscape, I want it show portrait immediate,
Is there any wrong setting?
EDIT
I called the error ViewController "vcA", it present from "vcB"
in vcB's viewDidAppear
, I called
[self presentViewController:vc animated:NO completion:nil];
then vcA will show in landscape(if vcB was in landscape),
if add a few delay like:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self presentViewController:vc animated:NO completion:nil];
});
it will show portrait, but I do not know why it happen!
ANSWER
Finally, I found root cause!
when I launch app, it stay in Portrait mode,
After launch, vcB is first VC I called,
Phone stay in landscape, so when
viewDidAppear
in vcB, it call rotate to LandscapeAt same time in viewDidAppear, I also call
present:vcA
So currently, view have to do both rotate to landscape and present vcA(should in Portrait!!)
Then the bad situation happened!
Solution
Just disable rotate for first launch in "vcB", then in viewDidAppear
, it will only call present:vcA
Thanks all a lot!