Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Back in 2010, <a href="https://stackoverflow.com/q/4357045/1318452">How to prevent a modal UIImagePickerController from rotating?</a> found no happy answer to this question.</p> <p>I found an alternative, but it's also like to get you rejected from the App Store: remove all observers from the window.</p> <p>If some part of your app outside a viewController needs orientation change messages, it can register for them:</p> <pre><code>[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]]; </code></pre> <p>The window, not surprisingly, registers for such notifications, then rotates the view controllers if they accept the new orientation. It's not conveniently watching for <code>UIDeviceOrientationDidChangeNotification</code>, so there must be a privately named equivalent. All you can do is remove <em>every</em> notification from the window:</p> <pre><code>[[NSNotificationCenter defaultCenter] removeObserver:[[self view] window]]; </code></pre> <p>There is no restoring this, if you just wanted to temporarily suppress orientation changes. Neither can we tell if the window was watching for any important notifications from other sources. It's incomplete, too - the button for turning over, and the button for taking a photo, move and rotate on their own.</p> <p><img src="https://i.stack.imgur.com/4SNy4.jpg" alt="Screenshot of iPad in landscape mode with camera UI still in portrait"></p> <p>How can you fix that quirk? You could switch off <code>showsCameraControls</code> on the UIImagePicker, and provide your own <code>cameraOverlayView</code> with the camera buttons on it. Or continue randomly removing notifications by traversing an entire view hierarchy (also rejection material) removing notifications from everything:</p> <pre><code>- (void) removeAllNotificationsFromView:(UIView*) view; { // This recurses through the view hierarchy removing all notifications for everything. // This is potentially destructive, and may result in rejection from the App Store. [[NSNotificationCenter defaultCenter] removeObserver:view]; for (UIView *subview in [view subviews]) [self removeAllNotificationsFromView:subview]; } [self removeAllNotificationsFromView:imagePicker.view]; </code></pre> <p>I don't recommend using this, but it provides some interesting insights into how orientation changes are detected and propagated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload