iOS 橫屏調(diào)用相冊

問題:最近在iPad開發(fā)中遇到的一個調(diào)用相冊的橫豎屏問題,正常調(diào)用相冊不管iPad是橫豎屏,開啟的相冊都是豎屏的---不多說直接上代碼

解決:給UIImagePickerViewController寫一個category 實現(xiàn)以下代碼

#import<UIKit/UIKit.h>

@interface UIImagePickerController (MyImagePicker)

- (BOOL)shouldAutorotate;

- (NSUInteger)supportedInterfaceOrientations;

@end

#import "UIImagePickerController+MyImagePicker.h"

@implementation UIImagePickerController (MyImagePicker)

- (BOOL)shouldAutorotate {

return YES;

}

- (NSUInteger)supportedInterfaceOrientations{

return UIInterfaceOrientationMaskLandscape;

}

@end

然后-->開啟相冊的時候通知Appdelegate,實現(xiàn)UIInterfaceOrientationMask=UIInterfaceOrientationMaskAll 如下代碼

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

_myInterfaceOrientation = UIInterfaceOrientationMaskLandscape;

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeDirection:) name:@"changeDirection" object:nil];

return YES;

}

- (void)dealloc{

[[NSNotificationCenter defaultCenter] removeObserver:self];

}

- (void)changeDirection:(NSNotification *)notice{

if ([notice.object isEqualToString:@"0"]) {

_myInterfaceOrientation = UIInterfaceOrientationMaskLandscapeRight;

}else{

_myInterfaceOrientation = UIInterfaceOrientationMaskAll;

}

}

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{

return _myInterfaceOrientation;

}

最后-->(代碼思路,如果有相同之處,不是故意為之)以下是demo地址:demo

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容