I have view that is displayed in landscape mode. I want to modally display a new view controller with a portrait orientation (so that is looks like it's sliding in from the right). Currently, when I execute the code below, it modally displays the new view controller in the same landscape orientation that the calling view controller has. How can I modally display a new view controller with a portrait orientation, from a view controller that has a landscape orientation?
Here's my existing code...
//This code is called from the landscape view controller
- (void)showPortraitViewControllerButtonTapped
{
MyViewController *vc = [MyViewController new];
UINaviationViewController *navVC = [[UINavigationViewController alloc] initWithRootViewController:vc];
[self presentViewController:navVC animated:YES completion:nil];
}
//Code inside the view controller that I want to modally display in portrait orientation
@implementation MyViewController
(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
@end
Thanks in adavnce for your wisdom!
Instead of forcing orientation over a controller, since all you are interested in is the transition, you should control the transition itself:
[self.navigationController.view.layer addAnimation:({
CATransition *transition = [CATransition animation];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromTop;
transition;
}) forKey:@"SlideFromRightInLandscapeLeft"];
[self.navigationController pushViewController:navVC animated:NO];
Note that instead of -presentViewController
, this uses -pushViewController
. Close your navVC like so:
[self.navigationController popViewControllerAnimated:YES];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.