Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is one simple solution to avoid changing the supported orientations of your app, and make the <code>UIImagePickerController</code> work correctly: return <code>UIInterfaceOrientationMaskAll</code> only when the picker has to be presented.</p> <p>You can do it simply subclassing UIApplication and using these two methods:</p> <pre><code>- (NSUInteger)supportedInterfaceOrientationsForWindow:(UIWindow *)window { UIViewController *topController = window.rootViewController; if ([self hasPicker:topController]) return UIInterfaceOrientationMaskAll; return [super supportedInterfaceOrientationsForWindow:window]; } -(BOOL)hasPicker:(UIViewController *)controller { BOOL hasPicker = NO; NSLog(@"Check Controller: %@", controller); if ([controller isKindOfClass:[UIImagePickerController class]]) return YES; for (UIViewController *child in controller.childViewControllers) { hasPicker = [self hasPicker:child]; if (hasPicker) return YES; } return NO; } </code></pre> <p>In the first method, you are overriding the default <code>supportedInterfaceOrientationsForWindows:</code> method. Every time the method is called, you check all the view controllers in the hierarchy (through <code>hasPicker:</code>, a recursive method). If an UIImagePickerController is found, you return <code>UIInterfaceOrientationMaskAll</code>, otherwise you return the default setting of your app.</p> <p>Another thing I suggest you: don't subclass <code>UIImagePickerController</code>, since Apple explicitly forbids it. Instead, use view controller containment as I did in this example: </p> <blockquote> <p><a href="https://github.com/lombax85/LandscapePicker" rel="nofollow">Landscape Picker Example</a></p> </blockquote> <p><strong>NOTE: The example code works only with <code>UIImagePickerController</code> containment. If you subclass it and add it through <code>presentViewController:</code> you may have to adjust the behavior of the <code>hasPicker:</code> method. One other simple thing you can do: add an instance variable to your <code>UIApplication</code> subclass and set it when you show the picker, and unset when you dismiss</strong></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.
    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