Skip to content

Commit bb7ad80

Browse files
committed
Let subviews can be using auto layout
Let subviews can be using auto layout
1 parent e5c0ca1 commit bb7ad80

File tree

13 files changed

+73
-28
lines changed

13 files changed

+73
-28
lines changed

MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ - (void)placeSubviews
6868
{
6969
[super placeSubviews];
7070

71+
if (self.gifView.constraints.count) return;
72+
7173
self.gifView.frame = self.bounds;
7274
if (self.isRefreshingTitleHidden) {
7375
self.gifView.contentMode = UIViewContentModeCenter;

MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ - (void)placeSubviews
4343
{
4444
[super placeSubviews];
4545

46+
if (self.loadingView.constraints.count) return;
47+
4648
// 圈圈
47-
CGFloat arrowCenterX = self.mj_w * 0.5;
49+
CGFloat loadingCenterX = self.mj_w * 0.5;
4850
if (!self.isRefreshingTitleHidden) {
49-
arrowCenterX -= 100;
51+
loadingCenterX -= 100;
5052
}
51-
CGFloat arrowCenterY = self.mj_h * 0.5;
52-
self.loadingView.center = CGPointMake(arrowCenterX, arrowCenterY);
53+
CGFloat loadingCenterY = self.mj_h * 0.5;
54+
self.loadingView.center = CGPointMake(loadingCenterX, loadingCenterY);
5355
}
5456

5557
- (void)setState:(MJRefreshState)state

MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ - (void)placeSubviews
7070
{
7171
[super placeSubviews];
7272

73+
if (self.stateLabel.constraints.count) return;
74+
7375
// 状态标签
7476
self.stateLabel.frame = self.bounds;
7577
}

MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ - (void)placeSubviews
7979
{
8080
[super placeSubviews];
8181

82+
if (self.gifView.constraints.count) return;
83+
8284
self.gifView.frame = self.bounds;
8385
if (self.stateLabel.hidden) {
8486
self.gifView.contentMode = UIViewContentModeCenter;

MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.m

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,24 @@ - (void)placeSubviews
5757
{
5858
[super placeSubviews];
5959

60-
// 箭头
61-
self.arrowView.mj_size = self.arrowView.image.size;
60+
// 箭头的中心点
6261
CGFloat arrowCenterX = self.mj_w * 0.5;
6362
if (!self.stateLabel.hidden) {
6463
arrowCenterX -= 100;
6564
}
6665
CGFloat arrowCenterY = self.mj_h * 0.5;
67-
self.arrowView.center = CGPointMake(arrowCenterX, arrowCenterY);
66+
CGPoint arrowCenter = CGPointMake(arrowCenterX, arrowCenterY);
67+
68+
// 箭头
69+
if (self.arrowView.constraints.count == 0) {
70+
self.arrowView.mj_size = self.arrowView.image.size;
71+
self.arrowView.center = arrowCenter;
72+
}
6873

6974
// 圈圈
70-
self.loadingView.frame = self.arrowView.frame;
75+
if (self.loadingView.constraints.count == 0) {
76+
self.loadingView.center = arrowCenter;
77+
}
7178
}
7279

7380
- (void)setState:(MJRefreshState)state

MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ - (void)placeSubviews
6363
{
6464
[super placeSubviews];
6565

66+
if (self.stateLabel.constraints.count) return;
67+
6668
// 状态标签
6769
self.stateLabel.frame = self.bounds;
6870
}

MJRefresh/Custom/Header/MJRefreshGifHeader.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ - (void)placeSubviews
8181
{
8282
[super placeSubviews];
8383

84+
if (self.gifView.constraints.count) return;
85+
8486
self.gifView.frame = self.bounds;
8587
if (self.stateLabel.hidden && self.lastUpdatedTimeLabel.hidden) {
8688
self.gifView.contentMode = UIViewContentModeCenter;

MJRefresh/Custom/Header/MJRefreshNormalHeader.m

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,24 @@ - (void)placeSubviews
5858
{
5959
[super placeSubviews];
6060

61-
// 箭头
62-
self.arrowView.mj_size = self.arrowView.image.size;
61+
// 箭头的中心点
6362
CGFloat arrowCenterX = self.mj_w * 0.5;
6463
if (!self.stateLabel.hidden) {
6564
arrowCenterX -= 100;
6665
}
6766
CGFloat arrowCenterY = self.mj_h * 0.5;
68-
self.arrowView.center = CGPointMake(arrowCenterX, arrowCenterY);
67+
CGPoint arrowCenter = CGPointMake(arrowCenterX, arrowCenterY);
6968

69+
// 箭头
70+
if (self.arrowView.constraints.count == 0) {
71+
self.arrowView.mj_size = self.arrowView.image.size;
72+
self.arrowView.center = arrowCenter;
73+
}
74+
7075
// 圈圈
71-
self.loadingView.frame = self.arrowView.frame;
76+
if (self.loadingView.constraints.count == 0) {
77+
self.loadingView.center = arrowCenter;
78+
}
7279
}
7380

7481
- (void)setState:(MJRefreshState)state

MJRefresh/Custom/Header/MJRefreshStateHeader.m

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ - (void)setTitle:(NSString *)title forState:(MJRefreshState)state
5555

5656
#pragma mark - 日历获取在9.x之后的系统使用currentCalendar会出异常。在8.0之后使用系统新API。
5757
- (NSCalendar *)currentCalendar {
58-
if (([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedDescending)) {
58+
if (NSFoundationVersionNumber >= NSFoundationVersionNumber_iOS_8_0) {
5959
return [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
6060
}
6161
return [NSCalendar currentCalendar];
@@ -116,21 +116,28 @@ - (void)placeSubviews
116116

117117
if (self.stateLabel.hidden) return;
118118

119+
BOOL noConstrainsOnStatusLabel = self.stateLabel.constraints.count == 0;
120+
119121
if (self.lastUpdatedTimeLabel.hidden) {
120122
// 状态
121-
self.stateLabel.frame = self.bounds;
123+
if (noConstrainsOnStatusLabel) self.stateLabel.frame = self.bounds;
122124
} else {
125+
CGFloat stateLabelH = self.mj_h * 0.5;
123126
// 状态
124-
self.stateLabel.mj_x = 0;
125-
self.stateLabel.mj_y = 0;
126-
self.stateLabel.mj_w = self.mj_w;
127-
self.stateLabel.mj_h = self.mj_h * 0.5;
127+
if (noConstrainsOnStatusLabel) {
128+
self.stateLabel.mj_x = 0;
129+
self.stateLabel.mj_y = 0;
130+
self.stateLabel.mj_w = self.mj_w;
131+
self.stateLabel.mj_h = stateLabelH;
132+
}
128133

129134
// 更新时间
130-
self.lastUpdatedTimeLabel.mj_x = 0;
131-
self.lastUpdatedTimeLabel.mj_y = self.stateLabel.mj_h;
132-
self.lastUpdatedTimeLabel.mj_w = self.mj_w;
133-
self.lastUpdatedTimeLabel.mj_h = self.mj_h - self.lastUpdatedTimeLabel.mj_y;
135+
if (self.lastUpdatedTimeLabel.constraints.count == 0) {
136+
self.lastUpdatedTimeLabel.mj_x = 0;
137+
self.lastUpdatedTimeLabel.mj_y = stateLabelH;
138+
self.lastUpdatedTimeLabel.mj_w = self.mj_w;
139+
self.lastUpdatedTimeLabel.mj_h = self.mj_h - self.lastUpdatedTimeLabel.mj_y;
140+
}
134141
}
135142
}
136143

MJRefreshExample/Base.lproj/LaunchScreen.xib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8191" systemVersion="15A284" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8191" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
33
<dependencies>
44
<deployment identifier="iOS"/>
55
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>

0 commit comments

Comments
 (0)