简体   繁体   中英

iOS 7 Landscape only app can't access photo library

I have a landscape only app and whenever I access the Photo library , app would crash (because UIImagePickerViewController is trying to load in portrait mode). App works fine in iOS 5 and 6 .

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation' , reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

*** First throw call stack:
(
    0   CoreFoundation                      0x0303c5e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x024028b6 objc_exception_throw + 44
    2   CoreFoundation                      0x0303c3bb +[NSException raise:format:] + 139
    3   UIKit                               0x0108b7b2 -[UIViewController __supportedInterfaceOrientations] + 509
    4   UIKit                               0x0108b7de -[UIViewController __withSupportedInterfaceOrientation:apply:] + 34
    5   UIKit                               0x0108be52 -[UIViewController setInterfaceOrientation:] + 139
    6   UIKit                               0x01080ca8 -[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:] + 946
    7   UIKit                               0x00fcdb48 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1530
    8   UIKit                               0x00fcd847 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 761
    9   UIKit                               0x00fc5070 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 162
    10  UIKit                               0x00fc4ef8 -[UIView(Hierarchy) _postMovedFromSuperview:] + 260
    11  UIKit                               0x00fd0031 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1847
    12  UIKit                               0x00fc3521 -[UIView(Hierarchy) addSubview:] + 56
    13  UIKit                               0x0128cc3f -[UINavigationTransitionView transition:fromView:toView:] + 501
    14  UIKit                               0x0128ca42 -[UINavigationTransitionView transition:toView:] + 55
    15  UIKit                               0x010a23d7 -[UINavigationController _startTransition:fromViewController:toViewController:] + 3186
    16  UIKit                               0x010a272c -[UINavigationController _startDeferredTransitionIfNeeded:] + 645
    17  UIKit                               0x010a3349 -[UINavigationController __viewWillLayoutSubviews] + 57
    18  UIKit                               0x011dc39d -[UILayoutContainerView layoutSubviews] + 213
    19  UIKit                               0x00fd2dd7 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
    20  libobjc.A.dylib                     0x0241481f -[NSObject performSelector:withObject:] + 70
    21  QuartzCore                          0x00d6872a -[CALayer layoutSublayers] + 148
    22  QuartzCore                          0x00d5c514 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    23  QuartzCore                          0x00d5c380 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
    24  QuartzCore                          0x00cc4156 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
    25  QuartzCore                          0x00cc54e1 _ZN2CA11Transaction6commitEv + 393
    26  QuartzCore                          0x00cc5bb4 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    27  CoreFoundation                      0x0300453e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    28  CoreFoundation                      0x0300448f __CFRunLoopDoObservers + 399
    29  CoreFoundation                      0x02fe23b4 __CFRunLoopRun + 1076
    30  CoreFoundation                      0x02fe1b33 CFRunLoopRunSpecific + 467
    31  CoreFoundation                      0x02fe194b CFRunLoopRunInMode + 123
    32  GraphicsServices                    0x032969d7 GSEventRunModal + 192
    33  GraphicsServices                    0x032967fe GSEventRun + 104
    34  UIKit                               0x00f6894b UIApplicationMain + 1225
    35  Kickass                             0x000027ad main + 141
    36  Kickass                             0x00002715 start + 53
    37  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Unfortunately, it seems that UIImagePickerViewController will only work in portrait mode. Only way I have found to fix this problem is to add Portrait mode support to app in plist but limit all other views to only support landscape.

Add below to all your views you don't want in portrait:

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

Credit for this answer goes to iOS 7 Landscape only app can't access photo library

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM