新建項目 打開終端 切換到項目目錄路徑 cd /Users/dc008/Desktop/OC/Masonry框架
ls查看目錄佈局
pod search 第三方框架的名字 動畫
若是沒有 ui
cuixiaoyu:testCoco dc008$ touch Podfilespa
cuixiaoyu:testCoco dc008$ open Podfile (在文件裏寫podfile內容).net
新建的項目用 pod install 安裝3d
以前的項目用 pod update 更新orm
Updating local specs repositories(正在更新)get
//animation
// ViewController.m
// Masonry
//
// Created by dc008 on 16/1/4.
// Copyright © 2016年 lin. All rights reserved.
//
#import "ViewController.h"
#import <Masonry/Masonry.h>
@interface ViewController ()
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// [self test1];
[self test2];
}
- (void)test1{
UIView *view1 = [[UIView alloc]init];
view1.backgroundColor = [UIColor orangeColor];
[self.view addSubview:view1];
//添加限制,約束
[view1 mas_makeConstraints:^(MASConstraintMaker *make){
//edges 邊
//insets 內邊距
//with 沒有功能,只是爲了可讀性更強
make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(10, 10, 10, 10));
// make.leftMargin.mas_equalTo(10);
// make.topMargin.mas_equalTo(10);
// make.rightMargin.mas_equalTo(10);
// make.bottomMargin.mas_equalTo(10);
}];
}
- (void)test2{
UIView *view1 = [[UIView alloc]init];
view1.backgroundColor = [UIColor purpleColor];
[self.view addSubview:view1];
UIView *view2 = [[UIView alloc]init];
view2.backgroundColor = [UIColor orangeColor];
[self.view addSubview:view2];
UIView *view3 = [[UIView alloc]init];
view3.backgroundColor = [UIColor blueColor];
[self.view addSubview:view3];
//增長約束
[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
// make.size.mas_equalTo(CGSizeMake(300, 300));
// make.width.mas_equalTo(100);
// make.left.mas_equalTo(self.view.mas_left).with.offset(10);
// make.centerY.mas_equalTo(self.view.mas_centerY);//讓view1的y座標的中點等於self.view的y座標中點
make.width.mas_equalTo(view2.mas_width);//寬度等於view2的寬度
make.left.mas_equalTo(self.view.mas_left).with.offset(10);//view1的左邊距
make.right.mas_equalTo(view2.mas_left).with.offset(-10);//view1的右邊距,相對view2來設置
make.top.mas_equalTo(self.view.mas_top).offset(10);
make.bottom.mas_equalTo(view3.mas_top).offset(-10);
}];
[view2 mas_makeConstraints:^(MASConstraintMaker *make) {
// make.centerY.mas_equalTo(self.view.mas_centerY);
make.width.mas_equalTo(view1.mas_width);
make.left.mas_equalTo(view1.mas_right).with.offset(10);
make.right.mas_equalTo(self.view.mas_right).with.offset(-10);
make.top.mas_equalTo(self.view.mas_top).offset(10);
make.bottom.mas_equalTo(view3.mas_top).offset(-10);
}];
[view3 mas_makeConstraints:^(MASConstraintMaker *make) {
// make.centerY.mas_equalTo(self.view.mas_centerY);
make.height.mas_equalTo(view1.mas_height);
make.width.mas_equalTo(self.view.mas_width).offset(-20);
make.top.mas_equalTo(view1.mas_bottom).offset(10);
make.bottom.mas_equalTo(-10);
make.left.mas_equalTo(self.view.mas_left).offset(10);
make.right.mas_equalTo(-10);
}];
//從無到有 顯示佈局動畫
[UIView animateWithDuration:3.0 animations:^{
[self.view layoutIfNeeded];//告知頁面佈局馬上更新
NSLog(@"%@",NSStringFromCGRect(view1.frame));
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end