@@ -101,12 +101,13 @@ -(void)loadView
101
101
// 添加,隐藏重新布局的布局。
102
102
[self addHideSubviewReLayoutLayout: contentLayout];
103
103
104
-
105
-
106
104
// 添加,自动伸缩布局
107
105
[self addShrinkLayout: contentLayout];
108
106
109
107
108
+ // 测试布局位置和布局尺寸的active属性。
109
+ [self addActiveLayout: contentLayout];
110
+
110
111
111
112
}
112
113
@@ -315,7 +316,6 @@ -(void)addShrinkLayout:(MyLinearLayout*)contentLayout
315
316
testLayout.padding = UIEdgeInsetsMake (10 , 10 , 10 , 10 );
316
317
testLayout.subviewHorzMargin = 10 ;
317
318
testLayout.subviewVertMargin = 10 ;
318
- testLayout.myBottomMargin = 50 ; // 这里设置底部间距的原因是登录按钮在最底部。为了使得滚动到底部时不被覆盖。
319
319
testLayout.heightDime .equalTo (@50 );
320
320
testLayout.clipsToBounds = YES ;
321
321
[contentLayout addSubview: testLayout];
@@ -335,6 +335,33 @@ -(void)addShrinkLayout:(MyLinearLayout*)contentLayout
335
335
336
336
}
337
337
338
+ // 这个例子用来描述布局位置和布局尺寸对象的active属性的使用。
339
+ -(void )addActiveLayout : (MyLinearLayout*)contentLayout
340
+ {
341
+ /*
342
+ 这个例子提供了1.3.1版本中MyLayoutSize和MyLayoutPos类新加入的属性active属性的使用方法。默认情况下这个属性的值都是YES表示指定的位置或者尺寸的设置是有效的,如果设置为NO则这个位置或者这个尺寸的设置将无效,不会对布局产生影响。因此你可以通过为位置对象或者尺寸对象设置是否为active来在运行中进行界面布局的动态调整。
343
+ */
344
+ MyLinearLayout *testLayout = [MyLinearLayout linearLayoutWithOrientation: MyLayoutViewOrientation_Vert];
345
+ testLayout.padding = UIEdgeInsetsMake (10 , 10 , 10 , 10 );
346
+ testLayout.backgroundColor = [UIColor whiteColor ];
347
+ testLayout.myTopMargin = 10 ;
348
+ testLayout.myBottomMargin = 50 ; // 这里设置底部间距的原因是登录按钮在最底部。为了使得滚动到底部时不被覆盖。你也可以设置contentLayout的bottomPadding = 50来解决这个问题。
349
+ [contentLayout addSubview: testLayout];
350
+
351
+ UIButton *testButton = [UIButton buttonWithType: UIButtonTypeSystem];
352
+ [testButton setTitle: @" Click me" forState: UIControlStateNormal];
353
+ testButton.backgroundColor = [CFTool color: 0 ];
354
+ testButton.heightDime .equalTo (@50 );
355
+ testButton.widthDime .equalTo (testButton.widthDime ).add (20 );
356
+ testButton.leftPos .equalTo (@10 ).active = YES ; // 左边边距是10,设置active为YES表示左边位置对象的设置是生效的。
357
+ testButton.rightPos .equalTo (@10 ).active = NO ; // 右边边距是10,设置active为NO表示右边位置对象的设置是不生效的。
358
+
359
+ [testButton addTarget: self action: @selector (handleActiveTest: ) forControlEvents: UIControlEventTouchUpInside];
360
+
361
+ [testLayout addSubview: testButton];
362
+
363
+ }
364
+
338
365
// 创建可执动作事件的布局
339
366
-(MyLinearLayout*)createActionLayout : (NSString *)title action : (SEL )action
340
367
{
@@ -739,6 +766,30 @@ -(void)handleClosePopmenu:(UIButton*)sender
739
766
740
767
}
741
768
769
+ -(void )handleActiveTest : (UIButton*)sender
770
+ {
771
+ // 下面代码中布局位置的active属性设置的变化所产生的效果。
772
+ if (sender.leftPos .isActive && sender.rightPos .isActive )
773
+ {
774
+ sender.leftPos .active = YES ;
775
+ sender.rightPos .active = NO ; // 按钮将停靠在父布局的左边。
776
+ }
777
+ else if (sender.leftPos .isActive )
778
+ {
779
+ sender.leftPos .active = NO ;
780
+ sender.rightPos .active = YES ; // 按钮将停靠在父布局的右边
781
+ }
782
+ else if (sender.rightPos .isActive )
783
+ {
784
+ sender.leftPos .active = YES ;
785
+ sender.rightPos .active = YES ; // 按钮的左右边距都生效,并且会拉伸按钮的宽度。
786
+ }
787
+
788
+ MyLinearLayout *superLayout = (MyLinearLayout*)sender.superview ;
789
+ [superLayout layoutAnimationWithDuration: 0.3 ];
790
+
791
+ }
792
+
742
793
/*
743
794
#pragma mark - Navigation
744
795
0 commit comments