Skip to content

Commit 9926077

Browse files
committedDec 4, 2016
add new API shouldSelectPlusChildViewController
1 parent f04a072 commit 9926077

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed
 

‎CYLTabBarController/CYLPlusButton.h

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
*/
5555
+ (UIViewController *)plusChildViewController;
5656

57+
+ (BOOL)shouldSelectPlusChildViewController;
58+
5759
#pragma mark - Deprecated API
5860

5961
+ (CGFloat)multiplerInCenterY CYL_DEPRECATED("Deprecated in 1.6.0. Use `+multiplierOfTabBarHeight:` instead.");

‎CYLTabBarController/CYLPlusButton.m

+7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ + (void)registerSubclass {
4545
#pragma clang diagnostic pop
4646

4747
- (void)plusChildViewControllerButtonClicked:(UIButton<CYLPlusButtonSubclassing> *)sender {
48+
BOOL notNeedConfigureSelectionStatus = [[self class] respondsToSelector:@selector(shouldSelectPlusChildViewController)] && ![[self class] shouldSelectPlusChildViewController];
49+
if (notNeedConfigureSelectionStatus) {
50+
return;
51+
}
52+
if (sender.selected) {
53+
return;
54+
}
4855
sender.selected = YES;
4956
[self cyl_tabBarController].selectedIndex = CYLPlusButtonIndex;
5057
}

‎CYLTabBarController/CYLTabBarController.m

+8-5
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,17 @@ - (void)offsetTabBarSwappableImageViewToFit:(CGFloat)swappableImageViewDefaultOf
268268

269269
#pragma mark - delegate
270270

271-
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController*)viewController {
271+
- (void)updateSelectionStatusIfNeededForTabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
272272
NSUInteger selectedIndex = tabBarController.selectedIndex;
273273
UIButton *plusButton = CYLExternPlusButton;
274-
if (CYLPlusChildViewController) {
275-
if ((selectedIndex == CYLPlusButtonIndex) && (viewController != CYLPlusChildViewController)) {
276-
plusButton.selected = NO;
277-
}
274+
BOOL shouldConfigureSelectionStatus = CYLPlusChildViewController && ((selectedIndex == CYLPlusButtonIndex) && (viewController != CYLPlusChildViewController));
275+
if (shouldConfigureSelectionStatus) {
276+
plusButton.selected = NO;
278277
}
278+
}
279+
280+
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
281+
[[self cyl_tabBarController] updateSelectionStatusIfNeededForTabBarController:tabBarController shouldSelectViewController:viewController];
279282
return YES;
280283
}
281284

‎CYLTabBarController/UIViewController+CYLTabBarControllerExtention.m

+4-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ - (void)checkTabBarChildControllerValidityAtIndex:(NSUInteger)index {
6666
@try {
6767
UIViewController *viewController;
6868
viewController = tabBarController.viewControllers[index];
69-
if (index != tabBarController.selectedIndex) {
70-
CYLExternPlusButton.selected = NO;
69+
UIButton *plusButton = CYLExternPlusButton;
70+
BOOL shouldConfigureSelectionStatus = (CYLPlusChildViewController) && ((index != CYLPlusButtonIndex) && (viewController != CYLPlusChildViewController));
71+
if (shouldConfigureSelectionStatus) {
72+
plusButton.selected = NO;
7173
}
7274
} @catch (NSException *exception) {
7375
NSString *formatString = @"\n\n\

‎Example/Classes/View/CYLPlusButtonSubclass.m

+11-2
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,20 @@ - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSIn
140140
// initWithRootViewController:plusChildViewController];
141141
// return plusChildNavigationController;
142142
//}
143-
144-
143+
//
145144
//+ (NSUInteger)indexOfPlusButtonInTabBar {
146145
// return 4;
147146
//}
147+
//
148+
//+ (BOOL)shouldSelectPlusChildViewController {
149+
// BOOL isSelected = CYLExternPlusButton.selected;
150+
// if (isSelected) {
151+
// NSLog(@"🔴类名与方法名:%@(在第%@行),描述:%@", @(__PRETTY_FUNCTION__), @(__LINE__), @"PlusButton is selected");
152+
// } else {
153+
// NSLog(@"🔴类名与方法名:%@(在第%@行),描述:%@", @(__PRETTY_FUNCTION__), @(__LINE__), @"PlusButton is not selected");
154+
// }
155+
// return YES;
156+
//}
148157

149158
+ (CGFloat)multiplierOfTabBarHeight:(CGFloat)tabBarHeight {
150159
return 0.3;

0 commit comments

Comments
 (0)