Force horizontal screen on ios camera interface
By default, cameras in IOS call systems use portrait screens. Many methods are found online to force landscape screens to be invalid. The following code is tested to be compatible with ios78.
Customize a UIImagePickerController and overwrite the following methods:
-(UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
Return UIInterfaceOrientationLandscapeLeft;
}
-(NSUInteger) supportedInterfaceOrientations {
Return UIInterfaceOrientationMaskLandscape;
}
-(BOOL) shouldAutorotate {
Return YES;
}
-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) interfaceOrientation {
If (UIInterfaceOrientationIsLandscape (interfaceOrientation )){
Return YES;
} Else {
Return NO;
}
}
To be compatible with ios8, add the following code to delegate:
-(NSUInteger) application :( UIApplication *) application supportedInterfaceOrientationsForWindow :( UIWindow *) window
{
NSString * strSubClass = [NSString stringwithuf8string: object_getClassName (window. rootViewController. presentedViewController)];
If ([@ "ImgTakeViewController" isEqualToString: strSubClass]) {
Return UIInterfaceOrientationMaskAll;
}
Return [application supportedInterfaceOrientationsForWindow: window];
}