首页 > 代码库 > iOS8的屏幕旋转的问题
iOS8的屏幕旋转的问题
判断横竖屏。http://www.cocoachina.com/ask/questions/show/121301
//self.cameraView是相机view - (NSUInteger)supportedInterfaceOrientations{ UIInterfaceOrientation e = [[UIApplication sharedApplication] statusBarOrientation]; if (e == UIInterfaceOrientationLandscapeLeft) { if (self.cameraView) { self.cameraView.transform = CGAffineTransformMakeRotation((-270 * M_PI) / 180.0f); } }else if (e == UIInterfaceOrientationLandscapeRight) { if (self.cameraView) { self.cameraView.transform = CGAffineTransformMakeRotation((270 * M_PI) / 180.0f); } } return (UIInterfaceOrientationMaskLandscape);} - (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. //m_bScreen是bool 型,判断横竖屏。 if ([[[UIDevice currentDevice]systemVersion ]floatValue] >= 8.0) { BOOL m_bScreen = NO; UIInterfaceOrientation e = [[UIApplication sharedApplication] statusBarOrientation]; if (e == UIInterfaceOrientationLandscapeLeft) { m_bScreen = NO; }else if (e == UIInterfaceOrientationLandscapeRight) { m_bScreen = YES; } if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) { NSNumber *num = [[NSNumber alloc] initWithInt:(m_bScreen?UIInterfaceOrientationLandscapeRight:UIInterfaceOrientationLandscapeLeft)]; [[UIDevice currentDevice] performSelector:@selector(setOrientation:) withObject:(id)num]; [UIViewController attemptRotationToDeviceOrientation];//这行代码是关键 } SEL selector=NSSelectorFromString(@"setOrientation:"); NSInvocation *invocation =[NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]]; [invocation setSelector:selector]; [invocation setTarget:[UIDevice currentDevice]]; int val =m_bScreen?UIInterfaceOrientationLandscapeRight:UIInterfaceOrientationLandscapeLeft; [invocation setArgument:&val atIndex:2]; [invocation invoke]; } }
获取相机view的方法:
#pragma mark UINavigationControllerDelegate- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ if ([[[UIDevice currentDevice]systemVersion ]floatValue] >= 8.0) { UIView *PLCameraView=[self findView:viewController.view withName:@"PLImagePickerCameraView"]; NSArray *svarray = [PLCameraView subviews]; self.imagePickerController.cameraView = svarray[0]; for (int i = 1; i < svarray.count; i++) { //i: 0 相机 1 拍照界面 2 重拍界面 if (i == 1) { NSArray *arr = [svarray[1] subviews]; for (int i = 0; i < arr.count; i++) { if (i == 9) { //i: 1 前置摄像头切换 [[arr objectAtIndex:i] setAlpha:0.0f]; } } } } }else if ([[[UIDevice currentDevice]systemVersion ]floatValue] >= 7.0) { UIView *PLCameraView=[self findView:viewController.view withName:@"PLCameraView"]; NSArray *svarray = [PLCameraView subviews]; for (int i = 1; i < svarray.count; i++) { //i: 0 相机 1 拍照界面 2 重拍界面 if (i == 1) { NSArray *arr = [svarray[1] subviews]; for (int i = 0; i < arr.count; i++) { if (i == 1) { //i: 1 前置摄像头切换 [[arr objectAtIndex:i] setAlpha:0.0f]; } } } } }}#pragma mark get/show the UIView we want//Find the view we want in camera structure.-(UIView *)findView:(UIView *)aView withName:(NSString *)name{ Class cl = [aView class]; NSString *desc = [cl description]; if ([name isEqualToString:desc]) return aView; for (NSUInteger i = 0; i < [aView.subviews count]; i++) { UIView *subView = [aView.subviews objectAtIndex:i]; subView = [self findView:subView withName:name]; if (subView) return subView; } return nil;}
iOS8的屏幕旋转的问题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。