适配横竖屏的两种方式

  1. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarOrientationChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];   
    
     - (void)statusBarOrientationChange:(NSNotification *)notification
    {
    
      UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    
     if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) {
     //翻转为竖屏时
       [self constrainsForPortrait];
       [self drawKline];
       [self drawLine];
       [self drawMA5];
       [self.tableView reloadData];
       }
      if (orientation==UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) {
         
         [self constrsinsForLandscape];
         [self drawKline];
         [self drawLine];
         [self drawMA5];
         [self.tableView reloadData];
         //考虑在里面重绘
       }
     }
    
  2.    - (NSInteger)needDrawKlineCount
     {
         CGFloat width = 0;
       UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
      if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) {
     
         width = SCREEN_WIDTH-50;
     
       }else{
         width = SCREEN_HEIGHT - 50;
     }
       _needDrawKlineCount = ceil(width/self.rowHeight);
       return _needDrawKlineCount;
     }
    
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 转自:http://www.code4app.com/blog-866962-1317.html1、设置UILab...
    MMOTE阅读 1,889评论 1 1
  • 1、设置UILabel行间距 NSMutableAttributedString* attrString = [[...
    十年一品温如言1008阅读 2,030评论 0 3
  • 1、设置UILabel行间距 NSMutableAttributedString* attrString = [[...
    FF_911阅读 1,497评论 0 3
  • 想给你幸福,却走不进你的世界。我想用我的全世界来换取一张通往你的世界的入场券,不过,那只不过是我的一厢情愿而已。我...
    萌婕阅读 264评论 0 1
  • 我经常接客,但那种客人,基本是相熟的,电话聊过,邮件发过,彼此都有了了解。在面对面相处时,坦然,自在,沟通起来,不...
    翟海莹阅读 867评论 0 2

友情链接更多精彩内容