Skip to content

Commit

Permalink
v1.11.0 new animation feature and new API
Browse files Browse the repository at this point in the history
v1.11.0 1)able to add animation to TabBar 2)add New API `-tabBarController:didSelectControl:`
  • Loading branch information
ChenYilong committed Jun 4, 2017
1 parent 06ec280 commit bcd6304
Show file tree
Hide file tree
Showing 17 changed files with 477 additions and 214 deletions.
2 changes: 1 addition & 1 deletion CYLTabBarController.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "CYLTabBarController"
s.version = "1.10.1"
s.version = "1.11.0"
s.summary = "Highly customizable tabBar and tabBarController for iOS"
s.description = "CYLTabBarController is iPad and iPhone compatible. Supports landscape and portrait orientations and can be used inside UINavigationController."
s.homepage = "https://github.com/ChenYilong/CYLTabBarController"
Expand Down
8 changes: 0 additions & 8 deletions CYLTabBarController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
9A1559DE1CB6D56500CAB1AF /* CYLDetailsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A1559D51CB6D56500CAB1AF /* CYLDetailsViewController.m */; };
9A1559DF1CB6D56500CAB1AF /* CYLSameCityViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A1559D71CB6D56500CAB1AF /* CYLSameCityViewController.m */; };
9A1559E41CB6EB1F00CAB1AF /* CYLPlusButtonSubclass.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A1559E31CB6EB1F00CAB1AF /* CYLPlusButtonSubclass.m */; };
9AB37B221DC869E1000782F2 /* README.md in Sources */ = {isa = PBXBuildFile; fileRef = 9AB37B211DC869E1000782F2 /* README.md */; };
9AB37B241DC869F2000782F2 /* issue_template.md in Sources */ = {isa = PBXBuildFile; fileRef = 9AB37B231DC869F2000782F2 /* issue_template.md */; };
9AE667131C800085001DED12 /* UIViewController+CYLTabBarControllerExtention.m in Sources */ = {isa = PBXBuildFile; fileRef = 9AE667121C800085001DED12 /* UIViewController+CYLTabBarControllerExtention.m */; };
9AE942E71BDC933E00354519 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9AE942CB1BDC933E00354519 /* LaunchScreen.xib */; };
9AE942E81BDC933E00354519 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9AE942CD1BDC933E00354519 /* Main.storyboard */; };
Expand Down Expand Up @@ -45,8 +43,6 @@
9A1559E21CB6EB1F00CAB1AF /* CYLPlusButtonSubclass.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CYLPlusButtonSubclass.h; sourceTree = "<group>"; };
9A1559E31CB6EB1F00CAB1AF /* CYLPlusButtonSubclass.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CYLPlusButtonSubclass.m; sourceTree = "<group>"; };
9A5B29111D3475BC009E1BEE /* CYLConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CYLConstants.h; sourceTree = "<group>"; };
9AB37B211DC869E1000782F2 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = SOURCE_ROOT; };
9AB37B231DC869F2000782F2 /* issue_template.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = issue_template.md; path = .github/issue_template.md; sourceTree = SOURCE_ROOT; };
9AE667111C800085001DED12 /* UIViewController+CYLTabBarControllerExtention.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+CYLTabBarControllerExtention.h"; sourceTree = "<group>"; };
9AE667121C800085001DED12 /* UIViewController+CYLTabBarControllerExtention.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+CYLTabBarControllerExtention.m"; sourceTree = "<group>"; };
9AE942741BDC91B800354519 /* CYLTabBarController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CYLTabBarController.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -182,8 +178,6 @@
9AE942E31BDC933E00354519 /* Images.xcassets */,
9AE942E41BDC933E00354519 /* Info.plist */,
9AE942E51BDC933E00354519 /* main.m */,
9AB37B211DC869E1000782F2 /* README.md */,
9AB37B231DC869F2000782F2 /* issue_template.md */,
);
path = Example;
sourceTree = "<group>";
Expand Down Expand Up @@ -294,9 +288,7 @@
9AE942F91BDC937F00354519 /* CYLPlusButton.m in Sources */,
9A1559C81CB6D4D300CAB1AF /* AppDelegate.m in Sources */,
9A1559DD1CB6D56500CAB1AF /* CYLMineViewController.m in Sources */,
9AB37B221DC869E1000782F2 /* README.md in Sources */,
9AE942FB1BDC937F00354519 /* CYLTabBarController.m in Sources */,
9AB37B241DC869F2000782F2 /* issue_template.md in Sources */,
9AE942F11BDC933E00354519 /* main.m in Sources */,
9AE942FA1BDC937F00354519 /* CYLTabBar.m in Sources */,
);
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Example/CYLTabBarControllerConfig.m"
timestampString = "505586344.471096"
timestampString = "518244204.694397"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "202"
endingLineNumber = "202"
startingLineNumber = "207"
endingLineNumber = "207"
landmarkName = "+imageWithColor:size:"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -36,27 +36,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CYLTabBarController/CYLTabBarController.m"
timestampString = "483515235.928086"
timestampString = "518268313.152042"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "70"
endingLineNumber = "70"
landmarkName = "-supportedInterfaceOrientations"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CYLTabBarController/CYLTabBarController.m"
timestampString = "483515235.928086"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "173"
endingLineNumber = "173"
startingLineNumber = "208"
endingLineNumber = "208"
landmarkName = "-setViewControllers:"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -68,11 +52,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CYLTabBarController/CYLTabBarController.m"
timestampString = "483515235.928086"
timestampString = "518268313.152042"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "171"
endingLineNumber = "171"
startingLineNumber = "206"
endingLineNumber = "206"
landmarkName = "-setViewControllers:"
landmarkType = "7">
<Locations>
Expand All @@ -84,11 +68,11 @@
moduleName = "CYLTabBarController"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/chenyilong/Documents/Git/%E7%AC%AC%E4%B8%89%E6%96%B9/CYLTabBarController/CYLTabBarController/CYLTabBarController.m"
timestampString = "505585873.800656"
timestampString = "518268577.264112"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "171"
endingLineNumber = "171"
startingLineNumber = "206"
endingLineNumber = "206"
offsetFromSymbolStart = "1380">
</Location>
<Location
Expand All @@ -99,11 +83,11 @@
moduleName = "CYLTabBarController"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/chenyilong/Documents/Git/%E7%AC%AC%E4%B8%89%E6%96%B9/CYLTabBarController/CYLTabBarController/CYLTabBarController.m"
timestampString = "505585873.802394"
timestampString = "518268577.267085"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "171"
endingLineNumber = "171"
startingLineNumber = "206"
endingLineNumber = "206"
offsetFromSymbolStart = "1395">
</Location>
</Locations>
Expand Down Expand Up @@ -144,31 +128,15 @@
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CYLTabBarController/CYLTabBarController.m"
timestampString = "505585386.994016"
timestampString = "518268313.152042"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "285"
endingLineNumber = "285"
landmarkName = "-updateSelectionStatusIfNeededForTabBarController:shouldSelectViewController:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CYLTabBarController/CYLTabBarController.m"
timestampString = "505585386.994016"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "291"
endingLineNumber = "291"
startingLineNumber = "326"
endingLineNumber = "326"
landmarkName = "-tabBarController:shouldSelectViewController:"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -180,27 +148,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CYLTabBarController/CYLTabBarController.m"
timestampString = "505585386.994016"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "282"
endingLineNumber = "282"
landmarkName = "-updateSelectionStatusIfNeededForTabBarController:shouldSelectViewController:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CYLTabBarController/CYLTabBarController.m"
timestampString = "505585451.639452"
timestampString = "518268313.152042"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "232"
endingLineNumber = "232"
startingLineNumber = "267"
endingLineNumber = "267"
landmarkName = "-getImageFromImageInfo:"
landmarkType = "7">
</BreakpointContent>
Expand Down
2 changes: 1 addition & 1 deletion CYLTabBarController/CYLPlusButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
+ (CGFloat)constantOfPlusButtonCenterYOffsetForTabBarHeight:(CGFloat)tabBarHeight;

/*!
* 实现该方法后,能让 PlusButton 的点击效果与跟点击其他 UITabBarButton 效果一样,跳转到该方法指定的 UIViewController 。
* 实现该方法后,能让 PlusButton 的点击效果与跟点击其他 TabBar 按钮效果一样,跳转到该方法指定的 UIViewController 。
* @attention 必须同时实现 `+indexOfPlusButtonInTabBar` 来指定 PlusButton 的位置。
* @return 指定 PlusButton 点击后跳转的 UIViewController。
*
Expand Down
33 changes: 24 additions & 9 deletions CYLTabBarController/CYLTabBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ - (instancetype)sharedInit {
*/
- (NSArray *)tabBarButtonArray {
if (_tabBarButtonArray == nil) {
NSArray *tabBarButtonArray = [[NSArray alloc] init];
_tabBarButtonArray = tabBarButtonArray;
_tabBarButtonArray = @[];
}
return _tabBarButtonArray;
}
Expand Down Expand Up @@ -251,19 +250,19 @@ - (void)setupSwappableImageViewDefaultOffset:(UIView *)tabBarButton {
* Capturing touches on a subview outside the frame of its superview.
*/
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
//1. 边界情况:不能响应点击事件

BOOL canNotResponseEvent = self.hidden || (self.alpha <= 0.01f) || (self.userInteractionEnabled == NO);
if (canNotResponseEvent) {
return nil;
}
if (!CYLExternPlusButton && ![self pointInside:point withEvent:event]) {
return nil;
}

//2. 优先处理 PlusButton (包括其突出的部分)、TabBarItems 未凸出的部分
//这一步主要是在处理只有两个 TabBarItems 的场景。

if (CYLExternPlusButton) {
CGRect plusButtonFrame = self.plusButton.frame;
BOOL isInPlusButtonFrame = CGRectContainsPoint(plusButtonFrame, point);
if (!isInPlusButtonFrame && (point.y < 0) ) {
return nil;
}
if (isInPlusButtonFrame) {
return CYLExternPlusButton;
}
Expand All @@ -275,10 +274,26 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
for (NSUInteger index = 0; index < tabBarButtons.count; index++) {
UIView *selectedTabBarButton = tabBarButtons[index];
CGRect selectedTabBarButtonFrame = selectedTabBarButton.frame;
if (CGRectContainsPoint(selectedTabBarButtonFrame, point)) {
BOOL isTabBarButtonFrame = CGRectContainsPoint(selectedTabBarButtonFrame, point);\
if (isTabBarButtonFrame) {
return selectedTabBarButton;
}
}

//3. 最后处理 TabBarItems 凸出的部分、添加到 TabBar 上的自定义视图、点击到 TabBar 上的空白区域

UIView *result = [super hitTest:point withEvent:event];
if (result) {
return result;
}

for (UIView *subview in self.subviews.reverseObjectEnumerator) {
CGPoint subPoint = [subview convertPoint:point fromView:self];
result = [subview hitTest:subPoint withEvent:event];
if (result) {
return result;
}
}
return nil;
}

Expand Down
37 changes: 30 additions & 7 deletions CYLTabBarController/CYLTabBarController.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@ FOUNDATION_EXTERN NSUInteger CYLPlusButtonIndex;
FOUNDATION_EXTERN CGFloat CYLPlusButtonWidth;
FOUNDATION_EXTERN CGFloat CYLTabBarItemWidth;

@interface CYLTabBarController : UITabBarController
@protocol CYLTabBarControllerDelegate <NSObject>

/*!
* @param tabBarController The tab bar controller containing viewController.
* @param control Selected UIControl in TabBar.
* @attention If PlusButton also add an action, then this delegate method will not be invoked when the PlusButton is selected.
*/
- (void)tabBarController:(UITabBarController *)tabBarController didSelectControl:(UIControl *)control;

@end

@interface CYLTabBarController : UITabBarController <CYLTabBarControllerDelegate>

/*!
* An array of the root view controllers displayed by the tab bar interface.
Expand All @@ -38,17 +49,29 @@ FOUNDATION_EXTERN CGFloat CYLTabBarItemWidth;
* To set both UIBarItem image view attributes in the tabBar,
* default is UIEdgeInsetsZero.
*/
@property (nonatomic, readwrite, assign) UIEdgeInsets imageInsets;
@property (nonatomic, readonly, assign) UIEdgeInsets imageInsets;

/*!
* To set both UIBarItem label text attributes in the tabBar,
* use the following to tweak the relative position of the label within the tab button (for handling visual centering corrections if needed because of custom text attributes)
*/
@property (nonatomic, readwrite, assign) UIOffset titlePositionAdjustment;
@property (nonatomic, readonly, assign) UIOffset titlePositionAdjustment;

- (instancetype)initWithViewControllers:(NSArray<UIViewController *> *)viewControllers
tabBarItemsAttributes:(NSArray<NSDictionary *> *)tabBarItemsAttributes;

+ (instancetype)tabBarControllerWithViewControllers:(NSArray<UIViewController *> *)viewControllers
tabBarItemsAttributes:(NSArray<NSDictionary *> *)tabBarItemsAttributes;

- (instancetype)initWithViewControllers:(NSArray<UIViewController *> *)viewControllers tabBarItemsAttributes:(NSArray<NSDictionary *> *)tabBarItemsAttributes;
- (instancetype)initWithViewControllers:(NSArray<UIViewController *> *)viewControllers
tabBarItemsAttributes:(NSArray<NSDictionary *> *)tabBarItemsAttributes
imageInsets:(UIEdgeInsets)imageInsets
titlePositionAdjustment:(UIOffset)titlePositionAdjustment;

+ (instancetype)tabBarControllerWithViewControllers:(NSArray<UIViewController *> *)viewControllers tabBarItemsAttributes:(NSArray<NSDictionary *> *)tabBarItemsAttributes;
+ (instancetype)tabBarControllerWithViewControllers:(NSArray<UIViewController *> *)viewControllers
tabBarItemsAttributes:(NSArray<NSDictionary *> *)tabBarItemsAttributes
imageInsets:(UIEdgeInsets)imageInsets
titlePositionAdjustment:(UIOffset)titlePositionAdjustment;

- (void)updateSelectionStatusIfNeededForTabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController;

Expand All @@ -68,12 +91,12 @@ FOUNDATION_EXTERN CGFloat CYLTabBarItemWidth;

@end

@interface NSObject (CYLTabBarController)
@interface NSObject (CYLTabBarControllerReferenceExtension)

/*!
* If `self` is kind of `UIViewController`, this method will return the nearest ancestor in the view controller hierarchy that is a tab bar controller. If `self` is not kind of `UIViewController`, it will return the `rootViewController` of the `rootWindow` as long as you have set the `CYLTabBarController` as the `rootViewController`. Otherwise return nil. (read-only)
*/
@property (nonatomic, readonly) CYLTabBarController *cyl_tabBarController;
@property (nonatomic, setter=cyl_setTabBarController:) CYLTabBarController *cyl_tabBarController;

@end

Expand Down
Loading

0 comments on commit bcd6304

Please sign in to comment.