IOS调用系统的相机默认是竖屏的,网上找了很多方法强制横屏都无效,以下代码经测试兼容ios78
自定义一个UIImagePickerController并且覆盖以下方法:
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return
UIInterfaceOrientationLandscapeLeft;
}
- (NSUInteger)supportedInterfaceOrientations{
return
UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotate {
return
YES;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
return
YES;
} else {
return
NO;
}
}
要兼容ios8还需要在delegate中加入以下代码
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow
*)window
{
NSString* strSubClass = [NSString
stringWithUTF8String:object_getClassName(window.rootViewController.presentedViewController)];
if ([@"ImgTakeViewController"
isEqualToString:strSubClass]) {
return
UIInterfaceOrientationMaskAll;
}
return [application
supportedInterfaceOrientationsForWindow:window];
}