在ipad开发中,很多时候软件需要固定横屏,由于UIImagePickerController只是支持竖屏,强行使用程序会崩溃。
解决方案
AppDelegate.h
@property (strong,nonatomic)NSString *OriFlag;
+ (AppDelegate *)appDelegate;
-(void)OrientationMask;
-(void)OrientationMaskBack;
AppDelegate.m
static AppDelegate *_appDelegate;
+ (AppDelegate *)appDelegate{
NSLog(@"调用");
return _appDelegate;
}
-(void)OrientationMask{
// NSLog(@"屏幕支持旋转");
self.OriFlag = @"1";
}
-(void)OrientationMaskBack{
// NSLog(@"屏幕禁止旋转");
self.OriFlag = @"2";
}
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if ([self.OriFlag isEqualToString:@"1"]) {
return UIInterfaceOrientationMaskAll;
NSLog(@"屏幕支持旋转");
}
return UIInterfaceOrientationMaskLandscapeRight;
}
在选取图片的时候调用
[[AppDelegate appDelegate]OrientationMask]; //屏幕支持旋转
在选取图片结束的时候调用[[AppDelegate appDelegate]OrientationMaskBack]; //屏幕禁止旋转