@@ -57,21 +57,12 @@ - (instancetype)sharedInit {
57
57
- (CGSize )sizeThatFits : (CGSize )size {
58
58
CGSize sizeThatFits = [super sizeThatFits: size];
59
59
CGFloat height = [self cyl_tabBarController ].tabBarHeight ;
60
- if (height > 0 && !CYL_IS_IPHONE_X && CYL_IS_IOS_11 ) {
60
+ if (height > 0 ) {
61
61
sizeThatFits.height = [self cyl_tabBarController ].tabBarHeight ;
62
62
}
63
63
return sizeThatFits;
64
64
}
65
65
66
- - (void )setFrame : (CGRect )frame {
67
- if (CYL_IS_IPHONE_X) {
68
- if (self.superview && CGRectGetMaxY (self.superview .bounds ) != CGRectGetMaxY (frame)) {
69
- frame.origin .y = CGRectGetHeight (self.superview .bounds ) - CGRectGetHeight (frame);
70
- }
71
- }
72
- [super setFrame: frame];
73
- }
74
-
75
66
/* *
76
67
* lazy load tabBarButtonArray
77
68
*
@@ -86,19 +77,19 @@ - (NSArray *)tabBarButtonArray {
86
77
87
78
- (void )layoutSubviews {
88
79
[super layoutSubviews ];
89
- CGFloat taBarWidth = self.bounds .size .width ;
90
- CGFloat taBarHeight = self.bounds .size .height ;
91
- CYLTabBarItemWidth = (taBarWidth - CYLPlusButtonWidth) / CYLTabbarItemsCount;
80
+ CGFloat tabBarWidth = self.bounds .size .width ;
81
+ CGFloat tabBarHeight = self.bounds .size .height ;
82
+ CYLTabBarItemWidth = (tabBarWidth - CYLPlusButtonWidth) / CYLTabbarItemsCount;
92
83
self.tabBarItemWidth = CYLTabBarItemWidth;
93
84
NSArray *sortedSubviews = [self sortedSubviews ];
94
85
self.tabBarButtonArray = [self tabBarButtonFromTabBarSubviews: sortedSubviews];
95
86
[self setupTabImageViewDefaultOffset: self .tabBarButtonArray[0 ]];
96
87
if (!CYLExternPlusButton) {
97
88
return ;
98
89
}
99
- CGFloat multiplierOfTabBarHeight = [self multiplierOfTabBarHeight: taBarHeight ];
100
- CGFloat constantOfPlusButtonCenterYOffset = [self constantOfPlusButtonCenterYOffsetForTabBarHeight: taBarHeight ];
101
- self.plusButton .center = CGPointMake (taBarWidth * 0.5 , taBarHeight * multiplierOfTabBarHeight + constantOfPlusButtonCenterYOffset);
90
+ CGFloat multiplierOfTabBarHeight = [self multiplierOfTabBarHeight: tabBarHeight ];
91
+ CGFloat constantOfPlusButtonCenterYOffset = [self constantOfPlusButtonCenterYOffsetForTabBarHeight: tabBarHeight ];
92
+ self.plusButton .center = CGPointMake (tabBarWidth * 0.5 , tabBarHeight * multiplierOfTabBarHeight + constantOfPlusButtonCenterYOffset);
102
93
NSUInteger plusButtonIndex = [self plusButtonIndex ];
103
94
[self .tabBarButtonArray enumerateObjectsUsingBlock: ^(UIView * _Nonnull childView, NSUInteger buttonIndex, BOOL * _Nonnull stop) {
104
95
// 调整UITabBarItem的位置
@@ -134,9 +125,13 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
134
125
}
135
126
if (context == CYLTabBarContext) {
136
127
[[NSNotificationCenter defaultCenter ] postNotificationName: CYLTabBarItemWidthDidChangeNotification object: self ];
128
+ if (CYL_IS_IPHONE_X && CYL_IS_IOS_11) {
129
+ [self layoutIfNeeded ];
130
+ }
137
131
}
138
132
}
139
133
134
+
140
135
- (void )dealloc {
141
136
// KVO反注册
142
137
[self removeObserver: self forKeyPath: @" tabBarItemWidth" ];
@@ -158,10 +153,10 @@ - (void)setTabImageViewDefaultOffset:(CGFloat)tabImageViewDefaultOffset {
158
153
}
159
154
}
160
155
161
- - (CGFloat )multiplierOfTabBarHeight : (CGFloat )taBarHeight {
156
+ - (CGFloat )multiplierOfTabBarHeight : (CGFloat )tabBarHeight {
162
157
CGFloat multiplierOfTabBarHeight;
163
158
if ([[self .plusButton class ] respondsToSelector: @selector (multiplierOfTabBarHeight: )]) {
164
- multiplierOfTabBarHeight = [[self .plusButton class ] multiplierOfTabBarHeight: taBarHeight ];
159
+ multiplierOfTabBarHeight = [[self .plusButton class ] multiplierOfTabBarHeight: tabBarHeight ];
165
160
}
166
161
167
162
#pragma clang diagnostic push
@@ -185,10 +180,10 @@ - (CGFloat)multiplierOfTabBarHeight:(CGFloat)taBarHeight {
185
180
return multiplierOfTabBarHeight;
186
181
}
187
182
188
- - (CGFloat )constantOfPlusButtonCenterYOffsetForTabBarHeight : (CGFloat )taBarHeight {
183
+ - (CGFloat )constantOfPlusButtonCenterYOffsetForTabBarHeight : (CGFloat )tabBarHeight {
189
184
CGFloat constantOfPlusButtonCenterYOffset = 0 .f ;
190
185
if ([[self .plusButton class ] respondsToSelector: @selector (constantOfPlusButtonCenterYOffsetForTabBarHeight: )]) {
191
- constantOfPlusButtonCenterYOffset = [[self .plusButton class ] constantOfPlusButtonCenterYOffsetForTabBarHeight: taBarHeight ];
186
+ constantOfPlusButtonCenterYOffset = [[self .plusButton class ] constantOfPlusButtonCenterYOffsetForTabBarHeight: tabBarHeight ];
192
187
}
193
188
return constantOfPlusButtonCenterYOffset;
194
189
}
@@ -257,7 +252,7 @@ - (void)setupTabImageViewDefaultOffset:(UIView *)tabBarButton {
257
252
shouldCustomizeImageView = NO ;
258
253
}
259
254
}];
260
- if (shouldCustomizeImageView && !CYL_IS_IPHONE_X ) {
255
+ if (shouldCustomizeImageView) {
261
256
self.tabImageViewDefaultOffset = tabImageViewDefaultOffset;
262
257
}
263
258
}
@@ -267,7 +262,6 @@ - (void)setupTabImageViewDefaultOffset:(UIView *)tabBarButton {
267
262
*/
268
263
- (UIView *)hitTest : (CGPoint )point withEvent : (UIEvent *)event {
269
264
// 1. 边界情况:不能响应点击事件
270
-
271
265
BOOL canNotResponseEvent = self.hidden || (self.alpha <= 0 .01f ) || (self.userInteractionEnabled == NO );
272
266
if (canNotResponseEvent) {
273
267
return nil ;
@@ -301,7 +295,6 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
301
295
}
302
296
303
297
// 3. 最后处理 TabBarItems 凸出的部分、添加到 TabBar 上的自定义视图、点击到 TabBar 上的空白区域
304
-
305
298
UIView *result = [super hitTest: point withEvent: event];
306
299
if (result) {
307
300
return result;
0 commit comments