• ios6内存警告和横竖屏处理解决方案


    文章转自:http://www.cnblogs.com/wqxlcdymqc/p/3214414.html

     http://www.cnblogs.com/iphone520/archive/2012/07/04/2575833.html

    如果我们新老版本都要支持的话,那么还需要再加些东西进去。

    - (void)didReceiveMemoryWarning 

    {

        [super didReceiveMemoryWarning];

        if([self isViewLoaded] && self.view.window == nil) 

        {

            self.view = nil;

        }

        sortedNames = nil;

        sortedValues = nil;

    }

     

    我们往往还要支持低版本的,所以在程序中,我们就需要保留之前的方法。

    但如果想要控制“UINavigationController”直接在Contoller中使用这个方法,将会不起作用,原因是ios6中“UINavigationController”并不支持

    - (BOOL)shouldAutorotate、

    - (NSUInteger)supportedInterfaceOrientations

    个方法,如果您想要控制其旋转,必须为其添加一个category,使其支持这个三个方法。

    @implementation UINavigationController (SupportIOS6)

     

    -(BOOL)shouldAutorotate

    {

          return[[self.viewControllers lastObject] shouldAutorotate];

    }

     

    -(NSUInteger)supportedInterfaceOrientations

          return[[self.viewControllers lastObject] supportedInterfaceOrientations];

    }

     

    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

    {

           return[[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];

    }

    @end

     

    强制横竖屏的解决方案:

    iOS6 

    让项目支持横竖屏  在具体页面 改变 supportedInterfaceOrientations

    -(BOOL)shouldAutorotate

    {

       return YES;

    }

    -(NSUInteger)supportedInterfaceOrientations

    {

      return UIInterfaceOrientationMaskLandscapeRight; //这里写你需要的方向。看好了,别写错了

    }

     

    强制转成横屏:iOS5可用

    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
          SEL selector = NSSelectorFromString(@"setOrientation:");
          NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
          [invocation setSelector:selector];
          [invocation setTarget:[UIDevice currentDevice]];
          int val = UIInterfaceOrientationLandscapeRight;
          [invocation setArgument:&val atIndex:2];
          [invocation invoke];
    }

    方法二: 通过判断状态栏来设置视图的transform属性。

     - (void)deviceOrientationDidChange: (NSNotification *)notification

    {

        UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];

        CGFloat startRotation = [[self valueForKeyPath:@"layer.transform.rotation.z"] floatValue];

        CGAffineTransform rotation;

        switch (interfaceOrientation) {

            case UIInterfaceOrientationLandscapeLeft:

                rotation = CGAffineTransformMakeRotation(-startRotation + M_PI * 270.0 / 180.0);

                break;

            case UIInterfaceOrientationLandscapeRight:

                rotation = CGAffineTransformMakeRotation(-startRotation + M_PI * 90.0 / 180.0);

                break;

            case UIInterfaceOrientationPortraitUpsideDown:

                rotation = CGAffineTransformMakeRotation(-startRotation + M_PI * 180.0 / 180.0);

                break;

            default:

                rotation = CGAffineTransformMakeRotation(-startRotation + 0.0);

                break;

        }

        view.transform = rotation;

    }

     

  • 相关阅读:
    分页查询
    web 开发中 405报错
    html 中input标签的name属性
    怎么样利用debug
    bzoj 1314: River过河 优先队列
    bzoj 4004: [JLOI2015]装备购买 拟阵 && 高消
    bzoj 1133: [POI2009]Kon dp
    bzoj 4127: Abs 树链剖分
    bzoj 2406: 矩阵 上下界网络流判定
    再写FFT模板
  • 原文地址:https://www.cnblogs.com/tomblogblog/p/3597197.html
Copyright © 2020-2023  润新知