• iOS学习之自定义视图时,在屏幕发生旋转时触发重新布局方法


    如果要对自定义的视图在屏幕旋转时重新布局,则在自定义视图中定义以下触发方法:

    -(void)layoutSubviews {
        [super layoutSubviews];
        //1.获取到屏幕旋转的方向
        UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
        //2.根据屏幕旋转方向布局子视图
        switch (orientation) {
                //竖直方向
            case UIDeviceOrientationPortrait:
                //倒立
            case UIDeviceOrientationPortraitUpsideDown:
            {
                CGRect fram = self.loginButton.frame;
                fram.origin.x = kMarginTop_LoginButton;
                fram.origin.y = kMarginTop_LoginButton;
                self.loginButton.frame = fram;
            }
                break;
                
                //右横屏
            case UIDeviceOrientationLandscapeRight:
                //左横屏
            case UIDeviceOrientationLandscapeLeft:
            {
                CGRect fram = self.loginButton.frame;
                fram.origin.x = kMarginLeft_LoginButton_Landscape;
                fram.origin.y = kMarginTop_DescripLabel;
                self.loginButton.frame = fram;
            }
                break;
                
            default:
                break;
        }
    }
  • 相关阅读:
    组合继承
    包装明星——封装
    多种添加公用方法的方式
    专有扩展
    插入标记
    mac 命令操作
    php(apache)切换版本
    SqlServer索引+约束篇章
    sqlserver 常用语法
    C# 通用数据访问类
  • 原文地址:https://www.cnblogs.com/ErosLii/p/4471112.html
Copyright © 2020-2023  润新知