zoukankan      html  css  js  c++  java
  • 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;
    
    }
  • 相关阅读:
    java自学
    java自学
    java自学
    java自学
    Interesting Finds: 2009 11.17 ~ 11.22
    Interesting Finds: 2009 10.09 ~10.13
    Interesting Finds: 2009 10.01 ~ 10.08
    Interesting Finds: 2009 10.14 ~ 10.21
    Interesting Finds: 2009 11.01 ~ 11.08
    Interesting Finds: 2009 10.25 ~ 10.31
  • 原文地址:https://www.cnblogs.com/yangmx/p/4045315.html
Copyright © 2011-2022 走看看