zoukankan      html  css  js  c++  java
  • 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;
        }
    }
  • 相关阅读:
    DeepLearning之路(三)MLP
    DeepLearning之路(二)SoftMax回归
    DeepLearning之路(一)逻辑回归
    自然语言处理工具
    一个 11 行 Python 代码实现的神经网络
    对联广告
    Java多线程
    QT数据库操作
    QT笔记
    C++基础入门
  • 原文地址:https://www.cnblogs.com/ErosLii/p/4471112.html
Copyright © 2011-2022 走看看