Force portrait orientation programmatically
(too old to reply)
Devarshi Kulshreshtha
2018-04-18 05:39:05 UTC
In our app we are supporting both orientations, however on selection of one
option we have to force user to remain only in portrait mode on all the
screens until he toggles it. So far we have found only this workable

[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeLeft)
[UINavigationController attemptRotationToDeviceOrientation];

Reference link: https://stackoverflow.com/a/26358192

The other solution which we tried is - returning NO from -shouldAutorotate
delegate. However the problem with this approach is that the delegate is
only called on currently displayed view controller not on previous view
controllers which might be behind it on navigation stack (or is presenting
view controller), hence only currently visible view controller starts
appearing in portrait mode, while previously displayed remain in landscape

I have two questions now:

Q1: Can our app be rejected from app store if we use the workable solution,
since we are trying to use the 'internal thing'?

Q2: What is the best approach to force set the orientation in app, at
runtime, say on tap of a button?

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to ***@ml-in.narkive.net

Continue reading on narkive: