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

news/2024/7/3 13:55:24

文章转自: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;

}

 

转载于:https://www.cnblogs.com/tomblogblog/p/3597197.html


http://www.niftyadmin.cn/n/1705917.html

相关文章

SpringBoot第19讲:SpringBoot 如何保证接口幂等

SpringBoot第19讲:SpringBoot 如何保证接口幂等 在以SpringBoot开发Restful接口时,如何防止接口的重复提交呢? 本文是SpringBoot第19讲,主要介绍接口幂等相关的知识点,并实践常见基于Token实现接口幂等。 文章目录 Spr…

刷人脸也可绿码,通过。

“您好,请出示健康码”疫情以来,健康码核验测温机已成为各场所日常必须进行的防范举措。健康码人脸识别测温一体机,不同于一般的红外线测温仪,不仅带有必备的测温功能,还有考勤、门禁、口罩识别、健康码核验功能。健康…

为什么插两条DDR400内存条会降为DDR333?

我用两根都是DDR400 512M的内存插在一起,两根都是双面的,电脑检测为DDR333,单独插任何一根都是DDR400,请高手解释一下原因?是由于都是双面的原因还是别的什么原因?因为我的主板说明书上写同时插两根DDR400 可能会降为D…

春运将近,防疫小门卫时刻守护您。

春运将近,作为人员密集的场所,也是作为最高风险级别的汽车站、高铁站等检票口,对于疫情防控的工作是特别重要的。某高铁站提出需求: 1、如何在室外测温,是否准确? 2、如何连接测温门跟健康码、身份证一体…

VB不同模块过程的调用、菜单的编辑

标准模块是多个窗体中的公共代码部分,只能存放通用过程,一个应用程序可以有多个标准模块 使用Dim或Static声明的变量称为局部变量,这种变量只在所定义的过程中有效,不同的过程中局部变量可以同名,因为他们占有不同的内…

手环,人脸也能自带健康码?

疫情防控期间,人人出示健康码既是每个人的义务又是作为每个公民的责任。可现实生活中我们常会遇到老人,小孩乘车、去超市时,无法出示健康码的问题,这无疑会对会直接对老人和小孩及不会出示健康码等人员的日常出行和生活方式造成不…

如何看CPU的前端总线和内存的频率

问:如何看CUP的前端总线和内存的频率? 答:一般在WINDOWS下是看不到的,可以在BOIS中查看。另外,可去华军软件园下个CUP-Z,就一目了然啦。http://www.onlinedown.net/soft/2775.htm。还有更强的系统分析工具…

主板前端总线频率,CPU前端总线频率,CPU主频和内存频率之间的关系

前端总线指的是CPU与内存之间的数据传输线。前端总线频率则是指CPU与内存之间的数据传输速率,它反映了CPU与内存之间的数据传输量或者说带宽,公式为:数据带宽(总线频率数据位宽)/8,8位就是一个字节1Byte8bit。CPU主频(…