码迷,mamicode.com
首页 > 移动开发 > 详细

iOS8的屏幕旋转的问题

时间:2014-10-23 12:13:03      阅读:289      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   io   os   ar   for   

判断横竖屏。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的屏幕旋转的问题

标签:des   style   blog   http   color   io   os   ar   for   

原文地址:http://www.cnblogs.com/yangmx/p/4045315.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!