@@ -68,18 +68,19 @@ - (NSArray *)tabBarButtonArray {
68
68
69
69
- (void )layoutSubviews {
70
70
[super layoutSubviews ];
71
- CGFloat barWidth = self.bounds .size .width ;
72
- CGFloat barHeight = self.bounds .size .height ;
73
- CYLTabBarItemWidth = (barWidth - CYLPlusButtonWidth) / CYLTabbarItemsCount;
71
+ CGFloat taBarWidth = self.bounds .size .width ;
72
+ CGFloat taBarHeight = self.bounds .size .height ;
73
+ CYLTabBarItemWidth = (taBarWidth - CYLPlusButtonWidth) / CYLTabbarItemsCount;
74
74
self.tabBarItemWidth = CYLTabBarItemWidth;
75
75
NSArray *sortedSubviews = [self sortedSubviews ];
76
76
self.tabBarButtonArray = [self tabBarButtonFromTabBarSubviews: sortedSubviews];
77
77
[self setupSwappableImageViewDefaultOffset: self .tabBarButtonArray[0 ]];
78
78
if (!CYLExternPlusButton) {
79
79
return ;
80
80
}
81
- CGFloat multiplerInCenterY = [self multiplerInCenterY ];
82
- self.plusButton .center = CGPointMake (barWidth * 0.5 , barHeight * multiplerInCenterY);
81
+ CGFloat multiplierOfTabBarHeight = [self multiplierOfTabBarHeight: taBarHeight];
82
+ CGFloat constantOfPlusButtonCenterYOffset = [self constantOfPlusButtonCenterYOffsetForTabBarHeight: taBarHeight];
83
+ self.plusButton .center = CGPointMake (taBarWidth * 0.5 , taBarHeight * multiplierOfTabBarHeight + constantOfPlusButtonCenterYOffset);
83
84
NSUInteger plusButtonIndex = [self plusButtonIndex ];
84
85
[self .tabBarButtonArray enumerateObjectsUsingBlock: ^(UIView * _Nonnull childView, NSUInteger buttonIndex, BOOL * _Nonnull stop) {
85
86
// 调整UITabBarItem的位置
@@ -139,22 +140,39 @@ - (void)setSwappableImageViewDefaultOffset:(CGFloat)swappableImageViewDefaultOff
139
140
}
140
141
}
141
142
142
- - (CGFloat )multiplerInCenterY {
143
- CGFloat multiplerInCenterY;
144
- if ([[self .plusButton class ] respondsToSelector: @selector (multiplerInCenterY )]) {
145
- multiplerInCenterY = [[self .plusButton class ] multiplerInCenterY ];
146
- } else {
143
+ - (CGFloat )multiplierOfTabBarHeight : (CGFloat )taBarHeight {
144
+ CGFloat multiplierOfTabBarHeight;
145
+ if ([[self .plusButton class ] respondsToSelector: @selector (multiplierOfTabBarHeight: )]) {
146
+ multiplierOfTabBarHeight = [[self .plusButton class ] multiplierOfTabBarHeight: taBarHeight];
147
+ }
148
+
149
+ #pragma clang diagnostic push
150
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
151
+ else if ([[self .plusButton class ] respondsToSelector: @selector (multiplerInCenterY )]) {
152
+ multiplierOfTabBarHeight = [[self .plusButton class ] multiplerInCenterY ];
153
+ }
154
+ #pragma clang diagnostic pop
155
+
156
+ else {
147
157
CGSize sizeOfPlusButton = self.plusButton .frame .size ;
148
158
CGFloat heightDifference = sizeOfPlusButton.height - self.bounds .size .height ;
149
159
if (heightDifference < 0 ) {
150
- multiplerInCenterY = 0.5 ;
160
+ multiplierOfTabBarHeight = 0.5 ;
151
161
} else {
152
162
CGPoint center = CGPointMake (self.bounds .size .height * 0.5 , self.bounds .size .height * 0.5 );
153
163
center.y = center.y - heightDifference * 0.5 ;
154
- multiplerInCenterY = center.y / self.bounds .size .height ;
164
+ multiplierOfTabBarHeight = center.y / self.bounds .size .height ;
155
165
}
156
166
}
157
- return multiplerInCenterY;
167
+ return multiplierOfTabBarHeight;
168
+ }
169
+
170
+ - (CGFloat )constantOfPlusButtonCenterYOffsetForTabBarHeight : (CGFloat )taBarHeight {
171
+ CGFloat constantOfPlusButtonCenterYOffset = 0 .f ;
172
+ if ([[self .plusButton class ] respondsToSelector: @selector (constantOfPlusButtonCenterYOffsetForTabBarHeight: )]) {
173
+ constantOfPlusButtonCenterYOffset = [[self .plusButton class ] constantOfPlusButtonCenterYOffsetForTabBarHeight: taBarHeight];
174
+ }
175
+ return constantOfPlusButtonCenterYOffset;
158
176
}
159
177
160
178
- (NSUInteger )plusButtonIndex {
0 commit comments