Skip to content

Commit f23bf7d

Browse files
committed
重大升级!0.支持scrollview内容自适应;1.任意添加或者修改约束不冲突;2.性能提升%40以上
1 parent 53de436 commit f23bf7d

11 files changed

Lines changed: 245 additions & 60 deletions

File tree

SDAutoLayout 测试 Demo.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
486A382D1C0D852C000D43E5 /* DemoVC6.m in Sources */ = {isa = PBXBuildFile; fileRef = 486A382C1C0D852C000D43E5 /* DemoVC6.m */; };
1011
487D3EB71BCB9EC700A66173 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 487D3EB61BCB9EC700A66173 /* main.m */; };
1112
487D3EBA1BCB9EC700A66173 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 487D3EB91BCB9EC700A66173 /* AppDelegate.m */; };
1213
487D3EBD1BCB9EC700A66173 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 487D3EBC1BCB9EC700A66173 /* ViewController.m */; };
@@ -54,6 +55,8 @@
5455
/* End PBXContainerItemProxy section */
5556

5657
/* Begin PBXFileReference section */
58+
486A382B1C0D852C000D43E5 /* DemoVC6.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoVC6.h; sourceTree = "<group>"; };
59+
486A382C1C0D852C000D43E5 /* DemoVC6.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoVC6.m; sourceTree = "<group>"; };
5760
487D3EB11BCB9EC700A66173 /* SDAutoLayout 测试 Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "SDAutoLayout 测试 Demo.app"; sourceTree = BUILT_PRODUCTS_DIR; };
5861
487D3EB51BCB9EC700A66173 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5962
487D3EB61BCB9EC700A66173 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
@@ -131,6 +134,15 @@
131134
/* End PBXFrameworksBuildPhase section */
132135

133136
/* Begin PBXGroup section */
137+
486A382A1C0D8499000D43E5 /* DemoVC6 */ = {
138+
isa = PBXGroup;
139+
children = (
140+
486A382B1C0D852C000D43E5 /* DemoVC6.h */,
141+
486A382C1C0D852C000D43E5 /* DemoVC6.m */,
142+
);
143+
name = DemoVC6;
144+
sourceTree = "<group>";
145+
};
134146
487D3EA81BCB9EC700A66173 = {
135147
isa = PBXGroup;
136148
children = (
@@ -197,6 +209,7 @@
197209
487D3EDE1BCBA52900A66173 /* DemoVC */ = {
198210
isa = PBXGroup;
199211
children = (
212+
486A382A1C0D8499000D43E5 /* DemoVC6 */,
200213
48DBCD051C01D82A002EC476 /* DemoVC5 */,
201214
487D3EBB1BCB9EC700A66173 /* ViewController.h */,
202215
487D3EBC1BCB9EC700A66173 /* ViewController.m */,
@@ -398,6 +411,7 @@
398411
487D3EBD1BCB9EC700A66173 /* ViewController.m in Sources */,
399412
48DA2B011BFB529200A771E6 /* UIView+SDAutoLayout.m in Sources */,
400413
487D3EF41BCBB71500A66173 /* DemoVC3.m in Sources */,
414+
486A382D1C0D852C000D43E5 /* DemoVC6.m in Sources */,
401415
48DBCD0E1C01DA1E002EC476 /* DemoVC5Model.m in Sources */,
402416
487D3EBA1BCB9EC700A66173 /* AppDelegate.m in Sources */,
403417
48DBCD0B1C01D89C002EC476 /* DemoVC5.m in Sources */,

SDAutoLayout 测试 Demo.xcodeproj/xcuserdata/gsd.xcuserdatad/xcschemes/SDAutoLayout 测试 Demo.xcscheme

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
</BuildActionEntries>
3838
</BuildAction>
3939
<TestAction
40+
buildConfiguration = "Debug"
4041
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4142
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
42-
shouldUseLaunchSchemeArgsEnv = "YES"
43-
buildConfiguration = "Debug">
43+
shouldUseLaunchSchemeArgsEnv = "YES">
4444
<Testables>
4545
<TestableReference
4646
skipped = "NO">
@@ -62,15 +62,18 @@
6262
ReferencedContainer = "container:SDAutoLayout &#x6d4b;&#x8bd5; Demo.xcodeproj">
6363
</BuildableReference>
6464
</MacroExpansion>
65+
<AdditionalOptions>
66+
</AdditionalOptions>
6567
</TestAction>
6668
<LaunchAction
69+
buildConfiguration = "Debug"
6770
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
6871
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
6972
launchStyle = "0"
7073
useCustomWorkingDirectory = "NO"
71-
buildConfiguration = "Debug"
7274
ignoresPersistentStateOnLaunch = "NO"
7375
debugDocumentVersioning = "YES"
76+
debugServiceExtension = "internal"
7477
allowLocationSimulation = "YES">
7578
<BuildableProductRunnable
7679
runnableDebuggingMode = "0">
@@ -86,10 +89,10 @@
8689
</AdditionalOptions>
8790
</LaunchAction>
8891
<ProfileAction
92+
buildConfiguration = "Release"
8993
shouldUseLaunchSchemeArgsEnv = "YES"
9094
savedToolIdentifier = ""
9195
useCustomWorkingDirectory = "NO"
92-
buildConfiguration = "Release"
9396
debugDocumentVersioning = "YES">
9497
<BuildableProductRunnable
9598
runnableDebuggingMode = "0">

SDAutoLayout 测试 Demo/DemoTableViewControler.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ - (void)viewDidLoad
4242

4343
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
4444
{
45-
return 6;
45+
return 7;
4646
}
4747

4848
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

SDAutoLayout 测试 Demo/DemoVC5CellTableViewCell.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ - (void)setup
9595
.leftEqualToView(_view2)
9696
.widthRatioToView(_view2, 0.7);
9797

98-
98+
_view0.sd_cornerRadiusFromWidthRatio = @(0.5);
9999
}
100100

101101
- (void)setModel:(DemoVC5Model *)model

SDAutoLayout 测试 Demo/DemoVC6.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// DemoVC6.h
3+
// SDAutoLayout 测试 Demo
4+
//
5+
// Created by gsd on 15/12/1.
6+
// Copyright © 2015年 gsd. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
#import "ViewController.h"
12+
13+
@interface DemoVC6 : ViewController
14+
15+
@end

SDAutoLayout 测试 Demo/DemoVC6.m

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//
2+
// DemoVC6.m
3+
// SDAutoLayout 测试 Demo
4+
//
5+
// Created by gsd on 15/12/1.
6+
// Copyright © 2015年 gsd. All rights reserved.
7+
//
8+
9+
#import "DemoVC6.h"
10+
11+
@interface DemoVC6 ()
12+
13+
@property (nonatomic, weak) UIScrollView *scrollView;
14+
15+
@end
16+
17+
@implementation DemoVC6
18+
19+
- (void)viewDidLoad {
20+
[super viewDidLoad];
21+
22+
UIScrollView *scrollView = [UIScrollView new];
23+
[self.view addSubview:scrollView];
24+
25+
[scrollView addSubview:self.view0];
26+
[scrollView addSubview:self.view1];
27+
[scrollView addSubview:self.view2];
28+
[scrollView addSubview:self.view3];
29+
[scrollView addSubview:self.view4];
30+
[scrollView addSubview:self.view5];
31+
[scrollView addSubview:self.view6];
32+
[scrollView addSubview:self.view7];
33+
[scrollView addSubview:self.view8];
34+
35+
36+
scrollView.sd_layout.spaceToSuperView(UIEdgeInsetsZero);
37+
38+
self.view0.sd_layout
39+
.leftSpaceToView(scrollView, 20)
40+
.rightSpaceToView(scrollView, 20)
41+
.topSpaceToView(scrollView, 20)
42+
.heightIs(150);
43+
44+
self.view1.sd_layout
45+
.widthIs(200)
46+
.heightIs(200)
47+
.centerXEqualToView(scrollView)
48+
.topSpaceToView(self.view0, 20);
49+
50+
self.view2.sd_layout
51+
.leftSpaceToView(scrollView, 50)
52+
.rightSpaceToView(scrollView, 50)
53+
.topSpaceToView(self.view1, 20)
54+
.heightIs(150);
55+
56+
self.view3.sd_layout
57+
.widthIs(250)
58+
.heightIs(250)
59+
.centerXEqualToView(scrollView)
60+
.topSpaceToView(self.view2, 20);
61+
62+
[scrollView setupAutoContentSizeWithBottomView:self.view3 bottomMargin:20];
63+
64+
65+
self.view0.sd_cornerRadiusFromHeightRatio = @(0.5);
66+
self.view1.sd_cornerRadiusFromWidthRatio = @(0.5);
67+
self.view2.sd_cornerRadiusFromWidthRatio = @(0.5);
68+
}
69+
70+
71+
72+
73+
@end

SDAutoLayout 测试 Demo/SDAutoLayout/UITableView+SDAutoTableViewCellHeight.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,6 @@
2525

2626
#define kSDModelCellTag 199206
2727

28-
29-
@interface UITableViewCell (SDAutoHeight)
30-
31-
@property (nonatomic) CGFloat autoHeight;
32-
33-
@property (nonatomic) UIView *sd_bottomView;
34-
@property (nonatomic) CGFloat sd_bottomViewBottomMargin;
35-
36-
- (void)setupAutoHeightWithBottomView:(UIView *)bottomView bottomMargin:(CGFloat)bottomMargin;
37-
38-
@end
39-
40-
4128
@interface SDCellAutoHeightManager : NSObject
4229

4330
@property (nonatomic, assign) CGFloat contentViewWidth;

SDAutoLayout 测试 Demo/SDAutoLayout/UITableView+SDAutoTableViewCellHeight.m

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,47 +25,6 @@
2525
#import "UIView+SDAutoLayout.h"
2626
#import <objc/runtime.h>
2727

28-
@implementation UITableViewCell (SDAutoHeight)
29-
30-
- (void)setupAutoHeightWithBottomView:(UIView *)bottomView bottomMargin:(CGFloat)bottomMargin
31-
{
32-
self.sd_bottomView = bottomView;
33-
self.sd_bottomViewBottomMargin = bottomMargin;
34-
self.sd_layout.autoHeightRatio(0);
35-
}
36-
37-
- (CGFloat)autoHeight
38-
{
39-
return [objc_getAssociatedObject(self, _cmd) floatValue];
40-
}
41-
42-
- (void)setAutoHeight:(CGFloat)autoHeight
43-
{
44-
objc_setAssociatedObject(self, @selector(autoHeight), @(autoHeight), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
45-
}
46-
47-
- (UIView *)sd_bottomView
48-
{
49-
return objc_getAssociatedObject(self, _cmd);
50-
}
51-
52-
- (void)setSd_bottomView:(UIView *)sd_bottomView
53-
{
54-
objc_setAssociatedObject(self, @selector(sd_bottomView), sd_bottomView, OBJC_ASSOCIATION_ASSIGN);
55-
}
56-
57-
- (CGFloat)sd_bottomViewBottomMargin
58-
{
59-
return [objc_getAssociatedObject(self, _cmd) floatValue];
60-
}
61-
62-
- (void)setSd_bottomViewBottomMargin:(CGFloat)sd_bottomViewBottomMargin
63-
{
64-
objc_setAssociatedObject(self, @selector(sd_bottomViewBottomMargin), @(sd_bottomViewBottomMargin), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
65-
}
66-
67-
@end
68-
6928
@implementation SDCellAutoHeightManager
7029
{
7130
NSMutableDictionary *_cacheDictionary;

SDAutoLayout 测试 Demo/SDAutoLayout/UIView+SDAutoLayout.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,31 @@ typedef void (^SpaceToSuperView)(UIEdgeInsets insets);
151151

152152

153153

154+
@interface UIView (SDAutoHeight)
154155

156+
@property (nonatomic) CGFloat autoHeight;
155157

158+
@property (nonatomic) UIView *sd_bottomView;
159+
@property (nonatomic) CGFloat sd_bottomViewBottomMargin;
156160

161+
- (void)setupAutoHeightWithBottomView:(UIView *)bottomView bottomMargin:(CGFloat)bottomMargin;
157162

163+
@end
164+
165+
@interface UIView (SDLayoutExtention)
166+
167+
@property (nonatomic, strong) NSNumber *sd_cornerRadius;
168+
@property (nonatomic, strong) NSNumber *sd_cornerRadiusFromWidthRatio;
169+
@property (nonatomic, strong) NSNumber *sd_cornerRadiusFromHeightRatio;
170+
171+
@end
172+
173+
174+
@interface UIScrollView (SDAutoContentSize)
175+
176+
- (void)setupAutoContentSizeWithBottomView:(UIView *)bottomView bottomMargin:(CGFloat)bottomMargin;
177+
178+
@end
158179

159180

160181

0 commit comments

Comments
 (0)