Skip to content

Commit

Permalink
update new feature red point
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenYilong committed Jun 14, 2017
1 parent a6c3be7 commit d333062
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 89 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ CYLTabBarController.xcodeproj/xcuserdata/chenyilong.xcuserdatad/xcdebugger/Break
*.xcuserstate
*.xcbkptlist
*.xcuserstate
*.xcbkptlist
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CYLTabBarController/CYLTabBarController.m"
timestampString = "519062970.556879"
timestampString = "519151512.189774"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "212"
Expand All @@ -52,7 +52,7 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CYLTabBarController/CYLTabBarController.m"
timestampString = "519062970.556879"
timestampString = "519151512.189913"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "210"
Expand All @@ -67,8 +67,8 @@
symbolName = "-[CYLTabBarController setViewControllers:]"
moduleName = "CYLTabBarController"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/chenyilong/Documents/CYL/CYLTabBarController/CYLTabBarController/CYLTabBarController.m"
timestampString = "519137468.917978"
urlString = "file:///Users/chenyilong/Documents/Git/%E7%AC%AC%E4%B8%89%E6%96%B9/CYLTabBarController/CYLTabBarController/CYLTabBarController.m"
timestampString = "519151624.53257"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "210"
Expand All @@ -82,8 +82,8 @@
symbolName = "-[CYLTabBarController setViewControllers:]"
moduleName = "CYLTabBarController"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/chenyilong/Documents/CYL/CYLTabBarController/CYLTabBarController/CYLTabBarController.m"
timestampString = "519137468.919809"
urlString = "file:///Users/chenyilong/Documents/Git/%E7%AC%AC%E4%B8%89%E6%96%B9/CYLTabBarController/CYLTabBarController/CYLTabBarController.m"
timestampString = "519151624.534434"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "210"
Expand All @@ -99,13 +99,13 @@
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CYLTabBarController/CYLPlusButton.m"
timestampString = "502563700.837366"
filePath = "CYLTabBarController/CYLTabBarController.m"
timestampString = "519151512.190002"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "63"
endingLineNumber = "63"
landmarkName = "+addSelectViewControllerTarget:"
startingLineNumber = "271"
endingLineNumber = "271"
landmarkName = "-getImageFromImageInfo:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
Expand All @@ -115,29 +115,29 @@
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CYLTabBarController/CYLPlusButton.m"
timestampString = "502563700.837366"
filePath = "CYLTabBarController/UIControl+CYLTabBarControllerExtention.m"
timestampString = "519152834.205129"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "62"
endingLineNumber = "62"
landmarkName = "+addSelectViewControllerTarget:"
startingLineNumber = "28"
endingLineNumber = "28"
landmarkName = "-cyl_setShowTabBadgePoint:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CYLTabBarController/CYLTabBarController.m"
timestampString = "519062970.556879"
filePath = "CYLTabBarController/CYLPlusButton.m"
timestampString = "519152834.2052"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "330"
endingLineNumber = "330"
landmarkName = "-tabBarController:shouldSelectViewController:"
startingLineNumber = "48"
endingLineNumber = "48"
landmarkName = "-plusChildViewControllerButtonClicked:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
Expand All @@ -147,13 +147,13 @@
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CYLTabBarController/CYLTabBarController.m"
timestampString = "519062970.556879"
filePath = "Example/AppDelegate.m"
timestampString = "519152834.205264"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "271"
endingLineNumber = "271"
landmarkName = "-getImageFromImageInfo:"
startingLineNumber = "96"
endingLineNumber = "96"
landmarkName = "-tabBarController:shouldSelectViewController:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
Expand Down
7 changes: 3 additions & 4 deletions CYLTabBarController/UIControl+CYLTabBarControllerExtention.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
- (void)cyl_removeTabBadgePoint;
- (BOOL)cyl_isShowTabBadgePoint;
- (void)cyl_setShowTabBadgePoint:(BOOL)showTabBadgePoint;

@property (nonatomic, strong, setter=cyl_setTabBadgePointView:, getter=cyl_tabBadgePointView) UIView *tabBadgePointView;

@property (nonatomic, assign, setter=cyl_setTabBadgePointViewOffset:, getter=cyl_tabBadgePointViewOffset) UIOffset tabBadgePointViewOffset;
//- (void)cyl_setTabBadgePointSize:(CGSize)size;
@property (nonatomic, strong, setter=cyl_setTabBadgePointView:, getter=cyl_tabBadgePointView) UIView *cyl_tabBadgePointView;
@property (nonatomic, assign, setter=cyl_setTabBadgePointViewOffset:, getter=cyl_tabBadgePointViewOffset) UIOffset cyl_tabBadgePointViewOffset;

@end
52 changes: 15 additions & 37 deletions CYLTabBarController/UIControl+CYLTabBarControllerExtention.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,35 @@ - (void)cyl_removeTabBadgePoint {
}

- (BOOL)cyl_isShowTabBadgePoint {
return !self.tabBadgePointView.hidden;
return !self.cyl_tabBadgePointView.hidden;
}

- (void)cyl_setShowTabBadgePoint:(BOOL)showTabBadgePoint {
if (showTabBadgePoint && self.tabBadgePointView.superview == nil) {
[self addSubview:self.tabBadgePointView];
[self bringSubviewToFront:self.tabBadgePointView];
self.tabBadgePointView.layer.zPosition = MAXFLOAT;
// X
if (showTabBadgePoint && self.cyl_tabBadgePointView.superview == nil) {
[self addSubview:self.cyl_tabBadgePointView];
[self bringSubviewToFront:self.cyl_tabBadgePointView];
self.cyl_tabBadgePointView.layer.zPosition = MAXFLOAT;
// X constraint
[self addConstraint:
[NSLayoutConstraint constraintWithItem:self.tabBadgePointView //self.cyl_imageView
[NSLayoutConstraint constraintWithItem:self.cyl_tabBadgePointView
attribute:NSLayoutAttributeCenterX
relatedBy:0
toItem:self.cyl_imageView
attribute:NSLayoutAttributeRight
multiplier:1
constant:self.tabBadgePointViewOffset.horizontal]];
//Y
constant:self.cyl_tabBadgePointViewOffset.horizontal]];
//Y constraint
[self addConstraint:
[NSLayoutConstraint constraintWithItem:self.tabBadgePointView //self.cyl_imageView
[NSLayoutConstraint constraintWithItem:self.cyl_tabBadgePointView
attribute:NSLayoutAttributeCenterY
relatedBy:0
toItem:self.cyl_imageView
attribute:NSLayoutAttributeTop
multiplier:1
constant:self.tabBadgePointViewOffset.vertical]];
constant:self.cyl_tabBadgePointViewOffset.vertical]];
}

self.tabBadgePointView.hidden = showTabBadgePoint == NO;
self.cyl_tabBadgePointView.hidden = showTabBadgePoint == NO;
self.cyl_tabBadgeView.hidden = showTabBadgePoint == YES;
}

Expand Down Expand Up @@ -109,6 +109,7 @@ - (UIImageView *)cyl_tabImageView {
}
return nil;
}

- (UILabel *)cyl_tabLabel {
for (UILabel *subview in self.subviews) {
if ([subview cyl_isTabLabel]) {
Expand All @@ -121,31 +122,8 @@ - (UILabel *)cyl_tabLabel {
#pragma mark - private method

- (UIView *)cyl_defaultTabBadgePointView {
CGFloat const defaultTabBadgePointViewRadius = 4.5;
UIView * defaultTabBadgePointView = [[UIView alloc] init];
[defaultTabBadgePointView setTranslatesAutoresizingMaskIntoConstraints:NO];
defaultTabBadgePointView.backgroundColor = [UIColor redColor];
defaultTabBadgePointView.layer.cornerRadius = defaultTabBadgePointViewRadius;
defaultTabBadgePointView.layer.masksToBounds = YES;
defaultTabBadgePointView.hidden = YES;
// Width constraint
[defaultTabBadgePointView addConstraint:[NSLayoutConstraint constraintWithItem:defaultTabBadgePointView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier:1
constant:defaultTabBadgePointViewRadius * 2]];

// Height constraint
[defaultTabBadgePointView addConstraint:[NSLayoutConstraint constraintWithItem:defaultTabBadgePointView
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier:1
constant:defaultTabBadgePointViewRadius * 2]];
return defaultTabBadgePointView;
UIView *defaultRedTabBadgePointView = [UIView cyl_tabBadgePointViewWithClolor:[UIColor redColor] radius:4.5];
return defaultRedTabBadgePointView;
}

@end
Expand Down
3 changes: 3 additions & 0 deletions CYLTabBarController/UIView+CYLTabBarControllerExtention.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface UIView (CYLTabBarControllerExtention)

Expand All @@ -16,4 +17,6 @@
- (BOOL)cyl_isTabLabel;
- (BOOL)cyl_isTabBadgeView;

+ (UIView *)cyl_tabBadgePointViewWithClolor:(UIColor *)color radius:(CGFloat)radius;

@end
26 changes: 26 additions & 0 deletions CYLTabBarController/UIView+CYLTabBarControllerExtention.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,30 @@ - (BOOL)cyl_classStringhasPrefix:(NSString *)subString {
return [classString hasPrefix:subString];
}

+ (UIView *)cyl_tabBadgePointViewWithClolor:(UIColor *)color radius:(CGFloat)radius {
UIView *defaultTabBadgePointView = [[UIView alloc] init];
[defaultTabBadgePointView setTranslatesAutoresizingMaskIntoConstraints:NO];
defaultTabBadgePointView.backgroundColor = color;
defaultTabBadgePointView.layer.cornerRadius = radius;
defaultTabBadgePointView.layer.masksToBounds = YES;
defaultTabBadgePointView.hidden = YES;
// Width constraint
[defaultTabBadgePointView addConstraint:[NSLayoutConstraint constraintWithItem:defaultTabBadgePointView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier:1
constant:radius * 2]];
// Height constraint
[defaultTabBadgePointView addConstraint:[NSLayoutConstraint constraintWithItem:defaultTabBadgePointView
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier:1
constant:radius * 2]];
return defaultTabBadgePointView;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ typedef void (^CYLPushOrPopCallback)(NSArray<__kindof UIViewController *> *viewC

@interface UIViewController (CYLTabBarControllerExtention)

@property (nonatomic, strong, setter=cyl_setTabBadgePointView:, getter=cyl_tabBadgePointView) UIView *tabBadgePointView;
@property (nonatomic, strong, setter=cyl_setTabBadgePointView:, getter=cyl_tabBadgePointView) UIView *cyl_tabBadgePointView;

@property (nonatomic, assign, setter=cyl_setTabBadgePointViewOffset:, getter=cyl_tabBadgePointViewOffset) UIOffset tabBadgePointViewOffset;
@property (nonatomic, assign, setter=cyl_setTabBadgePointViewOffset:, getter=cyl_tabBadgePointViewOffset) UIOffset cyl_tabBadgePointViewOffset;

@property (nonatomic, readonly, getter=cyl_isEmbedInTabBarController) BOOL cyl_embedInTabBarController;

Expand Down
59 changes: 40 additions & 19 deletions Example/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,46 @@ @interface AppDelegate ()<UITabBarControllerDelegate, CYLTabBarControllerDelegat
@end

@implementation AppDelegate
#define RANDOM_COLOR [UIColor colorWithHue: (arc4random() % 256 / 256.0) saturation:((arc4random()% 128 / 256.0 ) + 0.5) brightness:(( arc4random() % 128 / 256.0 ) + 0.5) alpha:1]

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 设置主窗口,并设置根控制器
self.window = [[UIWindow alloc]init];
self.window.frame = [UIScreen mainScreen].bounds;
[CYLPlusButtonSubclass registerPlusButton];
CYLTabBarControllerConfig *tabBarControllerConfig = [[CYLTabBarControllerConfig alloc] init];
[self.window setRootViewController:tabBarControllerConfig.tabBarController];
tabBarControllerConfig.tabBarController.delegate = self;
CYLTabBarController *tabBarController = tabBarControllerConfig.tabBarController;
[self.window setRootViewController:tabBarController];
[tabBarController setViewDidLayoutSubViewsBlock:^(CYLTabBarController *aTabBarController) {
UIViewController *viewController = aTabBarController.viewControllers[0];
UIView *tabBadgePointView0 = [UIView cyl_tabBadgePointViewWithClolor:RANDOM_COLOR radius:4.5];
[viewController.tabBarItem.cyl_tabButton cyl_setTabBadgePointView:tabBadgePointView0];
[viewController cyl_showTabBadgePoint];

UIView *tabBadgePointView1 = [UIView cyl_tabBadgePointViewWithClolor:RANDOM_COLOR radius:4.5];
[aTabBarController.viewControllers[1] cyl_setTabBadgePointView:tabBadgePointView1];
[aTabBarController.viewControllers[1] cyl_showTabBadgePoint];

UIView *tabBadgePointView2 = [UIView cyl_tabBadgePointViewWithClolor:RANDOM_COLOR radius:4.5];
[aTabBarController.viewControllers[2] cyl_setTabBadgePointView:tabBadgePointView2];
[aTabBarController.viewControllers[2] cyl_showTabBadgePoint];

[aTabBarController.viewControllers[3] cyl_showTabBadgePoint];

//添加提示动画,引导用户点击
[self addScaleAnimationOnView:aTabBarController.viewControllers[3].cyl_tabButton.cyl_tabImageView repeatCount:20];
}];

tabBarController.delegate = self;
[self.window makeKeyAndVisible];
[self customizeInterface];

[tabBarControllerConfig.tabBarController setViewDidLayoutSubViewsBlock:^(CYLTabBarController *tabBarController) {
[tabBarController.viewControllers[1] cyl_showTabBadgePoint];

[tabBarController.viewControllers[2] cyl_showTabBadgePoint];

[tabBarController.viewControllers[3] cyl_showTabBadgePoint];
}];

return YES;
}

- (void)customizeInterface {
[self setUpNavigationBarAppearance];

}

/**
Expand Down Expand Up @@ -84,35 +98,42 @@ - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectView
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectControl:(UIControl *)control {
if ([[self cyl_tabBarController].selectedViewController cyl_isShowTabBadgePoint]) {
[[self cyl_tabBarController].selectedViewController cyl_removeTabBadgePoint];
} else {
[[self cyl_tabBarController].selectedViewController cyl_showTabBadgePoint];
UIView *animationView;

if ([control cyl_isTabButton]) {
//更改红标状态
if ([[self cyl_tabBarController].selectedViewController cyl_isShowTabBadgePoint]) {
[[self cyl_tabBarController].selectedViewController cyl_removeTabBadgePoint];
} else {
[[self cyl_tabBarController].selectedViewController cyl_showTabBadgePoint];
}

animationView = [control cyl_tabImageView];
}

UIView *animationView;
// 即使 PlusButton 也添加了点击事件,点击 PlusButton 后也会触发该代理方法。
if ([control cyl_isPlusButton]) {
UIButton *button = CYLExternPlusButton;
animationView = button.imageView;
} else if ([control cyl_isTabButton]) {
animationView = [control cyl_tabImageView];
}



if ([self cyl_tabBarController].selectedIndex % 2 == 0) {
[self addScaleAnimationOnView:animationView];
[self addScaleAnimationOnView:animationView repeatCount:1];
} else {
[self addRotateAnimationOnView:animationView];
}
}

//缩放动画
- (void)addScaleAnimationOnView:(UIView *)animationView {
- (void)addScaleAnimationOnView:(UIView *)animationView repeatCount:(float)repeatCount {
//需要实现的帧动画,这里根据需求自定义
CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
animation.keyPath = @"transform.scale";
animation.values = @[@1.0,@1.3,@0.9,@1.15,@0.95,@1.02,@1.0];
animation.duration = 1;
animation.repeatCount = repeatCount;
animation.calculationMode = kCAAnimationCubic;
[animationView.layer addAnimation:animation forKey:nil];
}
Expand Down

0 comments on commit d333062

Please sign in to comment.