你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> ios 相機界面強制橫屏

ios 相機界面強制橫屏

編輯: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];

}


  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved