zoukankan      html  css  js  c++  java
  • autolayout的各种坑

    xocde7的autolayout

    在viewDidLoad之前, 使用frame改变布局是没有用的, 简单的视图才可以使用autolayout, 稍微复杂写的都要使用代码来编写

    获取当前view的宽度不再是使用self.view.frame.size.width, 因为autolayout下获取width是不真实的, 需要[uiscreen mainScreen].bounds.size.width来获取屏幕宽度

    [_xibView mas_updateConstraints:^(MASConstraintMaker *make) {

            make.top.offset(300);

            make.width.offset(100);

            make.height.offset(100);

        }];

     

    1. autolayout做动画需要调用系统方法

    [self.view layoutIfNeeded];

    例如:

    [UIView animateWithDuration:0.5 animations:^{
    //            CGRect rect = _xibView.frame;
    //            rect.origin.y = 300;
    //            _xibView.frame = rect;
    //            
                [_xibView mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.top.offset(300);
                    make.width.offset(100);
                    make.height.offset(100);
                }];
                [self.view layoutIfNeeded];
            } completion:^(BOOL finished) {
                
            }];

    2. 没办法知道这个视图的真实尺寸

    3. 难以修改或者这个视图的尺寸和位置约束

    4. 一个控制器包含多个子控制器

    我们需要把子控制器的view加入到当前控制器的view

    那么在viewDidLoad方法里设置子控制器的view.frame, 你会发现frame会被重置

    应该在viewWillAppear:animated 方法里面设置子控制器的view.frame

     5. UITableViewCell问题

    用惯了autolayout的uitablviewcell, 如果有一天你不使用autolayout, 记得把UITableViewCell的autolayout勾选给去掉, 

    不然的话你在cell的layoutsubview方法做出的布局更改是没有效果的

    记得clean project才有效果哦

    6.UIViewcontroller嵌套子控制器

    一般情况下是没有问题的, 但是加入在viewDidLoad方法里加入子控制器, 

    你就会发现, 你加入的子控制器根本没有显示出来

    (分析: 可能是因为, 如果使用autolayout, 进入viewdidload的时候, view的frame并没有被确定, 子控制器的视图的frame必须依靠父控制器的view的frame)

    但是父控制的view的frame这个时候恰好有没有办法确定, 所以出现了这种情况!

  • 相关阅读:
    yii 引入文件
    CodeForces 621C Wet Shark and Flowers
    面试题题解
    POJ 2251 Dungeon Master
    HDU 5935 Car(模拟)
    HDU 5938 Four Operations(暴力枚举)
    CodeForces 722C Destroying Array(并查集)
    HDU 5547 Sudoku(dfs)
    HDU 5583 Kingdom of Black and White(模拟)
    HDU 5512 Pagodas(等差数列)
  • 原文地址:https://www.cnblogs.com/apem/p/4573717.html
Copyright © 2011-2022 走看看