Coming soon - Get a detailed view of why an account is flagged as spam!
view details
54
Starting to go crazy, how do you present a view controller, allow it to rotate to landscape, but not have the presenting view controller rotate as well? Won't work with form sheet or custom presentations.
Post Body

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.

Author
Account Strength
100%
Account Age
14 years
Verified Email
Yes
Verified Flair
No
Total Karma
1,715,057
Link Karma
529,042
Comment Karma
607,499
Profile updated: 3 days ago
Posts updated: 5 months ago
Objective-C / Swift

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
5 years ago