ios 相机界面强制横屏
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];
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。