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];
}