zoukankan      html  css  js  c++  java
  • 屏幕的方向 重新布局的问题等

    在布局视图中

    - (instancetype)initWithFrame:(CGRect)frame {

     

        if (self = [super initWithFrame:frame]) {

            self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 200 , 200)];

            self.imageView.backgroundColor = [UIColor redColor];

            [self addSubview:self.imageView];

        }

        return self;

    }

     

    - (void)layoutSubviews {

    //    获取到屏幕的方向

    在这个方法中 屏幕旋转等会重新执行这个方法

        UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

        if (orientation == UIInterfaceOrientationLandscapeLeft) {

             self.imageView.frame = CGRectMake(200, 200, 20, 20);

        self.imageView.backgroundColor = [UIColor blackColor];

        }

        if (orientation == UIInterfaceOrientationLandscapeRight) {

            self.imageView.frame = CGRectMake(0, 200, 20, 20);

            self.imageView.backgroundColor = [UIColor blueColor];

        }  

    }

     

     

    在视图控制器中重写

    //屏幕支持的方向

    - (UIInterfaceOrientationMask)supportedInterfaceOrientations {

        return UIInterfaceOrientationMaskAll;//如果这里支持的方法固定,那么只会显示支持的那个方法下的设置。

    }

  • 相关阅读:
    vs2015调试慢
    阿里正式发布《Java开发手册》终极版!
    为什么听有些人讲话让人抓狂
    hibernate 映射实例 学生 课程 成绩
    hibernate 树状映射
    hibernate 一对多双向的CURD
    hibernate 多对多双向关联
    hibernate 多对多单向
    hibernate 一对多双向
    hibernate 一对多关联
  • 原文地址:https://www.cnblogs.com/naizui/p/5211578.html
Copyright © 2011-2022 走看看