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