Skip to content

Commit 946a025

Browse files
committed
Merge commit '49ee2671312ad356710ac478b6e0985f11549a99'
2 parents 2488652 + 49ee267 commit 946a025

8 files changed

Lines changed: 168 additions & 6 deletions

File tree

QMUI/QMUIKit/QMUIKit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ FOUNDATION_EXPORT const unsigned char QMUIKitVersionString[];
6060
#import <QMUIKit/QMUICellHeightCache.h>
6161
#import <QMUIKit/UITableView+QMUI.h>
6262
#import <QMUIKit/UICollectionView+QMUI.h>
63+
#import <QMUIKit/UITabBar+QMUI.h>
6364
#import <QMUIKit/UITabBarItem+QMUI.h>
6465
#import <QMUIKit/UIActivityIndicatorView+QMUI.h>
6566
#import <QMUIKit/UIWindow+QMUI.h>
@@ -148,6 +149,7 @@ FOUNDATION_EXPORT const unsigned char QMUIKitVersionString[];
148149
#import "QMUICellHeightCache.h"
149150
#import "UITableView+QMUI.h"
150151
#import "UICollectionView+QMUI.h"
152+
#import "UITabBar+QMUI.h"
151153
#import "UITabBarItem+QMUI.h"
152154
#import "UIActivityIndicatorView+QMUI.h"
153155
#import "UIWindow+QMUI.h"

QMUI/QMUIKit/UICommon/QMUIConfigurationManager.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,19 +232,19 @@ + (void)renderGlobalAppearances {
232232

233233
// UIToolBar
234234
UIToolbar *toolBarAppearance = [UIToolbar appearance];
235-
[toolBarAppearance setBarTintColor:ToolBarBarTintColor];
235+
toolBarAppearance.barTintColor = ToolBarBarTintColor;
236236
[toolBarAppearance setBackgroundImage:ToolBarBackgroundImage forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
237237
[toolBarAppearance setShadowImage:[UIImage qmui_imageWithColor:ToolBarShadowImageColor size:CGSizeMake(1, PixelOne) cornerRadius:0] forToolbarPosition:UIBarPositionAny];
238238

239239
// UITabBar
240240
UITabBar *tabBarAppearance = [UITabBar appearance];
241-
[tabBarAppearance setBarTintColor:TabBarBarTintColor];
242-
[tabBarAppearance setBackgroundImage:TabBarBackgroundImage];
241+
tabBarAppearance.barTintColor = TabBarBarTintColor;
242+
tabBarAppearance.backgroundImage = TabBarBackgroundImage;
243243
[tabBarAppearance setShadowImage:[UIImage qmui_imageWithColor:TabBarShadowImageColor size:CGSizeMake(1, PixelOne) cornerRadius:0]];
244244

245245

246246
// UITabBarItem
247-
UITabBarItem *tabBarItemAppearance = [UITabBarItem appearanceWhenContainedIn:[QMUITabBarViewController class], nil];
247+
UITabBarItem *tabBarItemAppearance = [UITabBarItem appearance];
248248
[tabBarItemAppearance setTitleTextAttributes:@{NSForegroundColorAttributeName:TabBarItemTitleColor} forState:UIControlStateNormal];
249249
[tabBarItemAppearance setTitleTextAttributes:@{NSForegroundColorAttributeName:TabBarItemTitleColorSelected} forState:UIControlStateSelected];
250250
}

QMUI/QMUIKit/UIKitExtensions/NSObject+QMUI.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ @implementation NSObject (QMUI)
1313

1414
- (BOOL)qmui_hasOverrideMethod:(SEL)selector ofSuperclass:(Class)superclass {
1515
if (![[self class] isSubclassOfClass:superclass]) {
16-
NSLog(@"%s, %@ 并非 %@ 的父类", __func__, NSStringFromClass(superclass), NSStringFromClass([self class]));
16+
// NSLog(@"%s, %@ 并非 %@ 的父类", __func__, NSStringFromClass(superclass), NSStringFromClass([self class]));
1717
return NO;
1818
}
1919

2020
if (![superclass instancesRespondToSelector:selector]) {
21-
NSLog(@"%s, 父类 %@ 自己本来就无法响应 %@ 方法", __func__, NSStringFromClass(superclass), NSStringFromSelector(selector));
21+
// NSLog(@"%s, 父类 %@ 自己本来就无法响应 %@ 方法", __func__, NSStringFromClass(superclass), NSStringFromSelector(selector));
2222
return NO;
2323
}
2424

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// UITabBar+QMUI.h
3+
// qmui
4+
//
5+
// Created by MoLice on 2017/2/14.
6+
// Copyright © 2017年 QMUI Team. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface UITabBar (QMUI)
12+
13+
@end
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
//
2+
// UITabBar+QMUI.m
3+
// qmui
4+
//
5+
// Created by MoLice on 2017/2/14.
6+
// Copyright © 2017年 QMUI Team. All rights reserved.
7+
//
8+
9+
#import "UITabBar+QMUI.h"
10+
#import "QMUICommonDefines.h"
11+
#import "UITabBarItem+QMUI.h"
12+
13+
NSInteger const kLastTouchedTabBarItemIndexNone = -1;
14+
15+
@interface UITabBar ()
16+
17+
@property(nonatomic, assign) BOOL canItemRespondDoubleTouch;
18+
@property(nonatomic, assign) NSInteger lastTouchedTabBarItemViewIndex;
19+
@property(nonatomic, assign) NSInteger tabBarItemViewTouchCount;
20+
@end
21+
22+
@implementation UITabBar (QMUI)
23+
24+
+ (void)load {
25+
static dispatch_once_t onceToken;
26+
dispatch_once(&onceToken, ^{
27+
ReplaceMethod([self class], @selector(setItems:animated:), @selector(qmui_setItems:animated:));
28+
ReplaceMethod([self class], @selector(setSelectedItem:), @selector(qmui_setSelectedItem:));
29+
});
30+
}
31+
32+
- (void)qmui_setItems:(NSArray<UITabBarItem *> *)items animated:(BOOL)animated {
33+
[self qmui_setItems:items animated:animated];
34+
35+
for (UITabBarItem *item in items) {
36+
if (!item.qmui_doubleTapBlock) {
37+
continue;
38+
}
39+
40+
UIControl *itemView = item.qmui_barButton;
41+
[itemView addTarget:self action:@selector(handleTabBarItemViewEvent:) forControlEvents:UIControlEventTouchUpInside];
42+
}
43+
}
44+
45+
- (void)qmui_setSelectedItem:(UITabBarItem *)selectedItem {
46+
NSInteger olderSelectedIndex = self.selectedItem ? [self.items indexOfObject:self.selectedItem] : -1;
47+
[self qmui_setSelectedItem:selectedItem];
48+
NSInteger newerSelectedIndex = [self.items indexOfObject:selectedItem];
49+
// 只有双击当前正在显示的界面的 tabBarItem,才能正常触发双击事件
50+
self.canItemRespondDoubleTouch = olderSelectedIndex == newerSelectedIndex;
51+
}
52+
53+
- (void)handleTabBarItemViewEvent:(UIControl *)itemView {
54+
55+
if (!self.canItemRespondDoubleTouch) {
56+
return;
57+
}
58+
59+
// 如果一定时间后仍未触发双击,则废弃当前的点击状态
60+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
61+
[self revertTabBarItemTouch];
62+
});
63+
64+
NSInteger selectedIndex = [self.items indexOfObject:self.selectedItem];
65+
66+
if (self.lastTouchedTabBarItemViewIndex == kLastTouchedTabBarItemIndexNone) {
67+
// 记录第一次点击的 index
68+
self.lastTouchedTabBarItemViewIndex = selectedIndex;
69+
} else if (self.lastTouchedTabBarItemViewIndex != selectedIndex) {
70+
// 后续的点击如果与第一次点击的 index 不一致,则认为是重新开始一次新的点击
71+
[self revertTabBarItemTouch];
72+
self.lastTouchedTabBarItemViewIndex = selectedIndex;
73+
return;
74+
}
75+
76+
self.tabBarItemViewTouchCount ++;
77+
if (self.tabBarItemViewTouchCount == 2) {
78+
// 第二次点击了相同的 tabBarItem,触发双击事件
79+
UITabBarItem *item = self.items[selectedIndex];
80+
if (item.qmui_doubleTapBlock) {
81+
item.qmui_doubleTapBlock(item, selectedIndex);
82+
}
83+
[self revertTabBarItemTouch];
84+
}
85+
}
86+
87+
- (void)revertTabBarItemTouch {
88+
self.lastTouchedTabBarItemViewIndex = kLastTouchedTabBarItemIndexNone;
89+
self.tabBarItemViewTouchCount = 0;
90+
}
91+
92+
#pragma mark - Swizzle Property Getter/Setter
93+
94+
static char kAssociatedObjectKey_canItemRespondDoubleTouch;
95+
- (void)setCanItemRespondDoubleTouch:(BOOL)canItemRespondDoubleTouch {
96+
objc_setAssociatedObject(self, &kAssociatedObjectKey_canItemRespondDoubleTouch, @(canItemRespondDoubleTouch), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
97+
}
98+
99+
- (BOOL)canItemRespondDoubleTouch {
100+
return [((NSNumber *)objc_getAssociatedObject(self, &kAssociatedObjectKey_canItemRespondDoubleTouch)) boolValue];
101+
}
102+
103+
static char kAssociatedObjectKey_lastTouchedTabBarItemViewIndex;
104+
- (void)setLastTouchedTabBarItemViewIndex:(NSInteger)lastTouchedTabBarItemViewIndex {
105+
objc_setAssociatedObject(self, &kAssociatedObjectKey_lastTouchedTabBarItemViewIndex, @(lastTouchedTabBarItemViewIndex), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
106+
}
107+
108+
- (NSInteger)lastTouchedTabBarItemViewIndex {
109+
return [((NSNumber *)objc_getAssociatedObject(self, &kAssociatedObjectKey_lastTouchedTabBarItemViewIndex)) integerValue];
110+
}
111+
112+
static char kAssociatedObjectKey_tabBarItemViewTouchCount;
113+
- (void)setTabBarItemViewTouchCount:(NSInteger)tabBarItemViewTouchCount {
114+
objc_setAssociatedObject(self, &kAssociatedObjectKey_tabBarItemViewTouchCount, @(tabBarItemViewTouchCount), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
115+
}
116+
117+
- (NSInteger)tabBarItemViewTouchCount {
118+
return [((NSNumber *)objc_getAssociatedObject(self, &kAssociatedObjectKey_tabBarItemViewTouchCount)) integerValue];
119+
}
120+
121+
@end

QMUI/QMUIKit/UIKitExtensions/UITabBarItem+QMUI.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010

1111
@interface UITabBarItem (QMUI)
1212

13+
/**
14+
* 双击 tabBarItem 时的回调,默认为 nil。
15+
* @arg tabBarItem 被双击的 UITabBarItem
16+
* @arg index 被双击的 UITabBarItem 的序号
17+
*/
18+
@property(nonatomic, copy) void (^qmui_doubleTapBlock)(UITabBarItem *tabBarItem, NSInteger index);
19+
1320
/**
1421
* 获取一个UITabBarItem内的按钮,里面包含imageView、label等子View
1522
*/

QMUI/QMUIKit/UIKitExtensions/UITabBarItem+QMUI.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,13 @@ - (UIImageView *)qmui_imageView {
3939
return nil;
4040
}
4141

42+
static char kAssociatedObjectKey_doubleTapBlock;
43+
- (void)setQmui_doubleTapBlock:(void (^)(UITabBarItem *, NSInteger))qmui_doubleTapBlock {
44+
objc_setAssociatedObject(self, &kAssociatedObjectKey_doubleTapBlock, qmui_doubleTapBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
45+
}
46+
47+
- (void (^)(UITabBarItem *, NSInteger))qmui_doubleTapBlock {
48+
return (void (^)(UITabBarItem *, NSInteger))objc_getAssociatedObject(self, &kAssociatedObjectKey_doubleTapBlock);
49+
}
50+
4251
@end

QMUI/qmui.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
CD78CBCF1DEE9E3500910DCE /* QMUIImagePreviewView.h in Headers */ = {isa = PBXBuildFile; fileRef = CD78CBCD1DEE9E3500910DCE /* QMUIImagePreviewView.h */; settings = {ATTRIBUTES = (Public, ); }; };
2929
CD78CBD01DEE9E3500910DCE /* QMUIImagePreviewView.m in Sources */ = {isa = PBXBuildFile; fileRef = CD78CBCE1DEE9E3500910DCE /* QMUIImagePreviewView.m */; };
3030
CD78CBD11DEE9E3500910DCE /* QMUIImagePreviewView.m in Sources */ = {isa = PBXBuildFile; fileRef = CD78CBCE1DEE9E3500910DCE /* QMUIImagePreviewView.m */; };
31+
CD84F31D1E52DBEA00546111 /* UITabBar+QMUI.h in Headers */ = {isa = PBXBuildFile; fileRef = CD84F31B1E52DBEA00546111 /* UITabBar+QMUI.h */; };
32+
CD84F31E1E52DBEA00546111 /* UITabBar+QMUI.m in Sources */ = {isa = PBXBuildFile; fileRef = CD84F31C1E52DBEA00546111 /* UITabBar+QMUI.m */; };
33+
CD84F31F1E52DBEA00546111 /* UITabBar+QMUI.m in Sources */ = {isa = PBXBuildFile; fileRef = CD84F31C1E52DBEA00546111 /* UITabBar+QMUI.m */; };
3134
CD9D18FC1DD462200020F268 /* QMUIFloatLayoutView.h in Headers */ = {isa = PBXBuildFile; fileRef = CD9D18FA1DD462200020F268 /* QMUIFloatLayoutView.h */; settings = {ATTRIBUTES = (Public, ); }; };
3235
CD9D18FD1DD462200020F268 /* QMUIFloatLayoutView.m in Sources */ = {isa = PBXBuildFile; fileRef = CD9D18FB1DD462200020F268 /* QMUIFloatLayoutView.m */; };
3336
CD9D18FE1DD462200020F268 /* QMUIFloatLayoutView.m in Sources */ = {isa = PBXBuildFile; fileRef = CD9D18FB1DD462200020F268 /* QMUIFloatLayoutView.m */; };
@@ -282,6 +285,8 @@
282285
CD78CBC91DEE9D6300910DCE /* QMUIImagePreviewViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QMUIImagePreviewViewController.m; sourceTree = "<group>"; };
283286
CD78CBCD1DEE9E3500910DCE /* QMUIImagePreviewView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QMUIImagePreviewView.h; sourceTree = "<group>"; };
284287
CD78CBCE1DEE9E3500910DCE /* QMUIImagePreviewView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QMUIImagePreviewView.m; sourceTree = "<group>"; };
288+
CD84F31B1E52DBEA00546111 /* UITabBar+QMUI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITabBar+QMUI.h"; sourceTree = "<group>"; };
289+
CD84F31C1E52DBEA00546111 /* UITabBar+QMUI.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITabBar+QMUI.m"; sourceTree = "<group>"; };
285290
CD9D18FA1DD462200020F268 /* QMUIFloatLayoutView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QMUIFloatLayoutView.h; sourceTree = "<group>"; };
286291
CD9D18FB1DD462200020F268 /* QMUIFloatLayoutView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QMUIFloatLayoutView.m; sourceTree = "<group>"; };
287292
CDB8CA2E1DCC870700769DF0 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -694,6 +699,8 @@
694699
CDB8CABD1DCC870700769DF0 /* UIViewController+QMUI.m */,
695700
CDB8CABE1DCC870700769DF0 /* UIWindow+QMUI.h */,
696701
CDB8CABF1DCC870700769DF0 /* UIWindow+QMUI.m */,
702+
CD84F31B1E52DBEA00546111 /* UITabBar+QMUI.h */,
703+
CD84F31C1E52DBEA00546111 /* UITabBar+QMUI.m */,
697704
);
698705
path = UIKitExtensions;
699706
sourceTree = "<group>";
@@ -789,6 +796,7 @@
789796
CDB8CB811DCC870700769DF0 /* QMUISegmentedControl.h in Headers */,
790797
CDB8CB8D1DCC870700769DF0 /* QMUITableViewCell.h in Headers */,
791798
CDB8CB511DCC870700769DF0 /* CALayer+QMUI.h in Headers */,
799+
CD84F31D1E52DBEA00546111 /* UITabBar+QMUI.h in Headers */,
792800
CDB8CBD91DCC870800769DF0 /* UIView+QMUI.h in Headers */,
793801
CDB8CB211DCC870700769DF0 /* QMUIOrderedDictionary.h in Headers */,
794802
CDB8CB451DCC870700769DF0 /* QMUITips.h in Headers */,
@@ -949,6 +957,7 @@
949957
CDB8CB4B1DCC870700769DF0 /* QMUIVisualEffectView.m in Sources */,
950958
CDB8CB7F1DCC870700769DF0 /* QMUISearchController.m in Sources */,
951959
16F6B6541DFEC39F00E58171 /* QMUIToastAnimator.m in Sources */,
960+
CD84F31E1E52DBEA00546111 /* UITabBar+QMUI.m in Sources */,
952961
CDB8CB931DCC870700769DF0 /* QMUITextField.m in Sources */,
953962
CDB8CB431DCC870700769DF0 /* QMUITestView.m in Sources */,
954963
CDB8CB971DCC870700769DF0 /* QMUITextView.m in Sources */,
@@ -1028,6 +1037,7 @@
10281037
CDB8CBD01DCC870800769DF0 /* UISearchBar+QMUI.m in Sources */,
10291038
CDB8CB781DCC870700769DF0 /* QMUILabel.m in Sources */,
10301039
CDB8CB4C1DCC870700769DF0 /* QMUIVisualEffectView.m in Sources */,
1040+
CD84F31F1E52DBEA00546111 /* UITabBar+QMUI.m in Sources */,
10311041
CDB8CB801DCC870700769DF0 /* QMUISearchController.m in Sources */,
10321042
CDB8CB941DCC870700769DF0 /* QMUITextField.m in Sources */,
10331043
CDB8CB441DCC870700769DF0 /* QMUITestView.m in Sources */,

0 commit comments

Comments
 (0)