zoukankan      html  css  js  c++  java
  • 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;

    }

     

  • 相关阅读:
    使用库项目实现Android程序代码的复用 java程序员
    编译触摸tslib出错:libtool: link: only absolute runpaths are allowed java程序员
    Linux下的TFTP软件的安装设置(TQ210)ubuntu11.10 java程序员
    拥有超过1200个PNG格式图标的免费图标集 Cosmo Mini java程序员
    Android Develop Training中文翻译06《Starting Another Activity》 java程序员
    周记二
    周记三
    周记
    周记
    周记
  • 原文地址:https://www.cnblogs.com/tomblogblog/p/3597197.html
Copyright © 2011-2022 走看看