zoukankan      html  css  js  c++  java
  • Masonry 一个约束第三方类库

    Masonry这个东东相当相当的牛掰,牛掰在哪呢,好用,相当的简单容易用。不愧为2000多个赞的第三方。

    来让我们看看具体用法。

    UIView *gr = UIView.new;
        gr.backgroundColor = [UIColor greenColor];
        UIView *re = UIView.new;
        re.backgroundColor = [UIColor redColor];
        UIView *ye = UIView.new;
        ye.backgroundColor = [UIColor yellowColor];
        [self.view addSubview:gr];
        [self.view addSubview:re];
        [self.view addSubview:ye];
        
        UIView *superView = self.view;
        
        [gr mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(superView.mas_left).offset(50);
            make.top.equalTo(superView.mas_top).offset(64+50);
            make.width.equalTo(@50);
            make.height.equalTo(@50);
        }];
        [re mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.greaterThanOrEqualTo(gr.mas_right).offset(20);
            make.top.equalTo(superView.mas_top).offset(64+70);
            make.width.equalTo(gr.mas_width).multipliedBy(2);
            make.height.equalTo(gr.mas_height).multipliedBy(2);
        }];
        [ye mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(re).insets(UIEdgeInsetsMake(20, 10, 15, 20));
    
        }];

    还是配一张图作为效果来看看吧

    先看图在看代码,简单易懂,定义三个颜色的视图,然后分别设定约束,block块里的就是约束,简单粗暴给力,除了一对一的设置,还可以用edge来一次设定视图约束,瞅瞅红色视图里包含的黄色视图就对了。

    然后他能做啥,看看这个

    基本包含了所有的枚举,然后在看看复合类型的:

    看到这里基本上能用了。但是我们还可以继续探索一些其他的功能:

    瞅瞅

    MASConstraint

    这个类,里面有很多block方法,都是用来获取约束对象的。具体功能请看API或者自己试试吧,哈哈。

    说个上面用的

    倍数约束multipliedBy,经常会需要根据屏幕尺寸来设定视图的size,那么这个可以帮助你搞定。

    顺便说一下对于UIScrollView应该怎么布局

    在约束UIScrollView的时候,如果希望横向滚动,就必须在UIScrollView的左右侧有约束。同样的,对于竖向滚动就必须在UIScrollView的上下侧有约束。


    另外有个方法mas_updateConstraints这个用来更新约束,约束更新了,问题出来了,必须得改变视图,那么可以采取做动画或者直接调用方法layoutIfNeeded:

    [UIView animateWithDuration:0.3 delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{
          [self.view layoutIfNeeded];
    }completion:NULL];
     
    天色已晚,有啥改天在写,看看demo,看看api,相信你能行的。。
    感谢强大的作者
  • 相关阅读:
    Java如何编写自动售票机程序
    install windows service
    redis SERVER INSTALL WINDOWS SERVICE
    上传文件
    This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.
    解决Uploadify上传控件加载导致的GET 404 Not Found问题
    OracleServiceORCL服务不见了怎么办
    Access to the temp directory is denied. Identity 'NT AUTHORITYNETWORK SERVICE' under which XmlSerializer is running does not have sufficient permiss
    MSSQL Server 2008 数据库安装失败
    数据库数据导出成XML文件
  • 原文地址:https://www.cnblogs.com/lingzhiguiji/p/4058422.html
Copyright © 2011-2022 走看看