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;

}
时间: 2024-10-12 06:23:34

iOS8的屏幕旋转的问题的相关文章

ios实现屏幕旋转的方法

1.屏蔽AppDelegate下面的屏幕旋转方法 #pragma mark - 屏幕旋转的 //- (UIInterfaceOrientationMask)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window //{ // return UIInterfaceOrientationMaskPortrait; //} 2.对UINavigationContr

UI基础:视图控制器.屏幕旋转.MVC

UIViewController 视图控制器,继承自UIResponder,作用:管理视图并且响应事件 功能: 1.分担APPdelegate的工作 2.实现模块独立,能提高复用性 创建UIViewController对象: UIViewController *viewController=[[UIViewController alloc]init]; UIViewController 自身带了一个UiView,默认的大小和屏幕大小一样. 每一个window都带有一个根视图,如果不给根视图赋值,

Android 屏幕旋转 处理 AsyncTask 和 ProgressDialog 的最佳方案

出处:http://blog.csdn.net/lmj623565791/article/details/37936275 1.概述 众所周知,Activity在不明确指定屏幕方向和configChanges时,当用户旋转屏幕会重新启动.当然了,应对这种情况,Android给出了几种方案: a.如果是少量数据,可以通过onSaveInstanceState()和onRestoreInstanceState()进行保存与恢复. Android会在销毁你的Activity之前调用onSaveInst

1016-03-父子控制器-----屏幕旋转事件的传递

1. ARC里面默认情况下所有指针都是强指针. 2. 在演示 设置两个控制器的关系为 父子控制器的关系的时候,将一个控制器B 的view加到 A控制器的view上去的时候,如果A.B不为父子控制器的关系时,旋转屏幕 的时候 B控制器是不能监听到屏幕的旋转的.只有A控制器可以监听到屏幕旋转. 3. 屏幕旋转事件是由窗口发出的.窗口会将事件传给它的根控制器. /** 监听旋转 */ - (void)willRotateToInterfaceOrientation:(UIInterfaceOrient

ios(ipad,iphone)屏幕旋转检测通用方法

在特别的场景下,需要针对屏幕旋转作特殊处理.在ios系统下实现相关的功能还是比较方便的. 我下面介绍两种方法: 1.注册UIApplicationDidChangeStatusBarOrientationNotification通知(举例:在一个viewcontroller类的viewdidload中注册该通知),示例代码如下: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarO

屏幕旋转学习笔记

加速计是整个IOS屏幕旋转的基础,依赖加速计,设备才可以判断出当前的设备方向,IOS系统共定义了以下七种设备方向: typedef NS_ENUM(NSInteger, UIDeviceOrientation) {     UIDeviceOrientationUnknown,     UIDeviceOrientationPortrait,            // Device oriented vertically, home button on the bottom     UIDev

iOS屏幕旋转方向的相关方法

在iOS应用开发过程中,经常会遇到设置屏幕方向,或者根据屏幕方向改变界面的时候,所以现在就来说一下屏幕方向的那些事情. 关于方向,经常会遇到以下的两个对象: 1.UIDeviceOrientation(机器设备的方向) ================================== UIDeviceOrientationUnknown //未知方向 UIDeviceOrientationPortrait, //设备直立,home按钮在下 UIDeviceOrientationPortrai

iOS学习笔记(3)— 屏幕旋转

iOS学习笔记(3)— 屏幕旋转 一.屏幕旋转机制: iOS通过加速计判断当前的设备方向和屏幕旋转.当加速计检测到方向变化的时候,屏幕旋转的流程如下: 1.设备旋转时,系统接收到旋转事件. 2.系统将旋转事件通过AppDelegate通知当前的主Window. 3.window通知它的rootViewController. 4.rootViewController判断所支持的旋转方向,完成旋转. iOS系统中屏幕旋转事件没有像触碰事件那样进行hitTest,所以只有rootViewControl

屏幕旋转

视图控制器本身能检测到屏幕的旋转,如果要处理屏幕旋转,需要重写方法 supportedInterfaceOrientations(设置设备支持旋转的方法, 如果不添加,视图控制器将无法检测到屏幕的旋转) 旋转后键盘收回 的方法 - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator 视图控制器会自动