Basically I have two view controllers: A and B. I want A to present B (think of it like a media viewer when you tap on an image).
View Controller A cannot go into landscape, it's only portrait. View Controller B, however (the media viewer) is perfectly able to.
When B rotates to landscape, how do I prevent A from rotating as well? If I use the AppDelegate
method supportedInterfaceOrientationsFor:
and set A to be .portrait
and B to be .allButUpsideDown
, it works. Hurrah!
However, being a fancy media viewer, I really want View Controller B to be presented with a custom animation. But as soon as I set modalPresentationStyle = .custom
on B, View Controller A no longer stays in portrait, it happily goes into landscape as well. The issue is that the AppDelegate
method is no longer called on dismissal, seemingly.
How can I prevent this? For what it's worth, I see the official Twitter app has this functionality on the iPhone X/XS where it only allows the feed in portrait but the media viewer in landscape. It's driving me batty trying to recreate the behaviour.
Here's a simple sample project showing all the code ready to be compiled that you can play around with if you're so inclined: https://drive.google.com/file/d/1b6x2lcVq6VUr2sAEWYdX57ahDZs1MDGT/view?usp=sharing
I'll give you Reddit Gold and a credit inside my Reddit app Apollo if you manage to figure it out. :D
EDIT: One nugget of info I've discerned is that viewDidAppear
doesn't get called on A when B is dismissed if set to custom. You can fix this by calling beginAppearanceTransition
and endAppearanceTransition
in the right spots (see code in comments) but it doesn't alleviate the issue. It does make me wonder though maybe iOS thinks that it's no longer a full screen presentation (even though it is) and to rotate the view controller in the background too for consistency's sake? If so I wonder if you can disable that behavior…
EDIT: Believe it's solved, see my comment with updates below.
Subreddit
Post Details
- Posted
- 5 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/iOSProgramm...