@@ -28,6 +28,22 @@ MyLayout是一套iOS界面视图布局框架。MyLayout的内核是基于对UIVi
28
28
[ http://www.jianshu.com/p/0c075f2fdab2 ] ( http://www.jianshu.com/p/0c075f2fdab2 ) 浮动布局
29
29
30
30
31
+ ### MyLayout的优势
32
+ * MyLayout的实现内核是基于frame的设置,而不是对AutoLayout的封装。因此在使用上不会受到任何操作系统版本的限制。
33
+ * 有文章表明用frame进行布局的性能要高于用AutoLayout进行布局的性能,尤其是当界面内视图数量增加时效果更加明显。
34
+ * AutoLayout的思想是通过视图之间的约束依赖来完成布局,但是约束依赖的结果是造成视图之间的耦合性高而增大了界面更新的成本。而MyLayout则除了提供约束依赖外,还提供了根据视图添加顺序自动建立约束的功能,从而减少了这种显示依赖关系建立的问题,最终的结果是简化了布局的代码量,以及减少了布局更新时的代码修改量。
35
+ * AutoLayout只是一种相对约束的布局,而MyLayout除了同时提供具有和AutoLayout相同能力的相对布局外、还提供了线性布局、框架布局、表格布局、流式布局、浮动布局、路径布局7大布局体系,你完全可以根据你的界面需求来选择一种最简易的布局容器来实现你的功能,同时MyLayout还支持Size classes的机制,以及提供了一些实现屏幕尺寸完美适配的方法。
36
+ * MyLayout主要是一种通过代码进行布局的解决方案,但是框架一样可以支持和XIB以及SB结合布局的方式。并提供了视图隐藏和显示时会自动激发布局、布局视图的高度自适应(UITableviewCell动态高度)、标签云实现、左右内容宽度自适应、按比例分配尺寸和间距、整体停靠控制等等各种强大的功能。
37
+
38
+
39
+ ### AutoLayout和frame布局的性能比较
40
+ ![ ] ( http://upload-images.jianshu.io/upload_images/1432482-e7e8c36e1b790d92.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240 )
41
+ ![ ] ( http://upload-images.jianshu.io/upload_images/1432482-69bddc21e9c9df5f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240 )
42
+
43
+ 参考的文章地址:[ http://floriankugler.com/2013/04/22/auto-layout-performance-on-ios/ ] ( http://floriankugler.com/2013/04/22/auto-layout-performance-on-ios/ )
44
+
45
+
46
+
31
47
## 演示效果图
32
48
33
49
![ 演示效果图] ( https://raw.githubusercontent.com/youngsoft/MyLinearLayout/master/MyLayout/layoutdemo1.gif )
@@ -49,38 +65,40 @@ MyLayout是一套iOS界面视图布局框架。MyLayout的内核是基于对UIVi
49
65
50
66
最终的效果图如下:
51
67
52
- ![ demo] (https://raw.githubusercontent.com/youngsoft/TangramKit/master/TangramKitDemo/Support Files /usagedemo.png)
68
+ ![ demo] ( https://raw.githubusercontent.com/youngsoft/TangramKit/master/TangramKitDemo/Support%20Files /usagedemo.png )
53
69
54
70
55
71
``` objective-c
56
72
57
- MyLinearLayout *S = [MyLinearLayout linearLayoutWithOrientation: MyLayoutViewOrientation_Vert] ;
73
+ MyLinearLayout *S = [MyLinearLayout linearLayoutWithOrientation: MyLayoutViewOrientation_Vert] ;
58
74
S.subviewMargin = 10;
59
- S.myWidth = 100;
60
-
75
+ S.widthDime.equalTo( @ 100 ) ;
76
+
61
77
UIView * A = UIView.new;
62
- A.myLeftMargin = 0.2;
63
- A.myRightMargin = 0.3;
78
+ A.leftPos.equalTo( @ 0 .2) ;
79
+ A.rightPos.equalTo( @ 0 .3) ;
64
80
A.heightDime.equalTo(A.widthDime);
65
81
[ S addSubview: A ] ;
66
82
67
83
UIView * B = UIView.new;
68
- B.myLeftMargin = 40 ;
69
- B.myWidth = 60 ;
70
- B.myHeight = 40 ;
84
+ B.leftPos.equalTo( @ 40 ) ;
85
+ B.widthDime.equalTo( @ 60 ) ;
86
+ B.heightDime.equalTo( @ 40 ) ;
71
87
[ S addSubview: B ] ;
72
88
73
89
UIView * C = UIView.new;
74
- C.myLeftMargin = C.myRightMargin = 0;
75
- C.myHeight = 40;
90
+ C.leftPos.equalTo(@0 );
91
+ C.rightPos.equalTo(@0 );
92
+ C.heightDime.equalTo(@40 );
76
93
[ S addSubview: C ] ;
77
94
78
95
UIView * D = UIView.new;
79
- D.myRightMargin = 20 ;
96
+ D.rightPos.equalTo( @ 20 ) ;
80
97
D.widthDime.equalTo(S.widthDime).multiply(0.5);
81
- D.myHeight = 40 ;
98
+ D.heightDime.equalTo( @ 40 ) ;
82
99
[ S addSubview: D ] ;
83
100
101
+
84
102
85
103
```
86
104
0 commit comments