Skip to content

Commit 33afad6

Browse files
committed
2.7.1
1 parent d87cf14 commit 33afad6

29 files changed

Lines changed: 230 additions & 323 deletions

QMUIKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "QMUIKit"
3-
s.version = "2.7.0"
3+
s.version = "2.7.1"
44
s.summary = "致力于提高项目 UI 开发效率的解决方案"
55
s.description = <<-DESC
66
QMUI iOS 是一个致力于提高项目 UI 开发效率的解决方案,其设计目的是用于辅助快速搭建一个具备基本设计还原效果的 iOS 项目,同时利用自身提供的丰富控件及兼容处理, 让开发者能专注于业务需求而无需耗费精力在基础代码的设计上。不管是新项目的创建,或是已有项目的维护,均可使开发效率和项目质量得到大幅度提升。

QMUIKit/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>2.7.0</string>
18+
<string>2.7.1</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

QMUIKit/QMUIComponents/ImagePickerLibrary/QMUIImagePickerPreviewViewController.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ - (void)viewDidLayoutSubviews {
125125
}
126126
}
127127

128+
- (BOOL)prefersStatusBarHidden {
129+
return YES;
130+
}
131+
128132
- (void)setToolBarBackgroundColor:(UIColor *)toolBarBackgroundColor {
129133
_toolBarBackgroundColor = toolBarBackgroundColor;
130134
self.topToolBarView.backgroundColor = self.toolBarBackgroundColor;

QMUIKit/QMUIComponents/QMUIBadge/UIBarItem+QMUIBadge.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121

2222
#pragma mark - Badge
2323

24-
/// 设置未读数,0 则隐藏未读数
25-
@property(nonatomic, assign) NSUInteger qmui_badgeValue;
24+
/// 用数字设置未读数,0表示不显示未读数
25+
@property(nonatomic, assign) NSUInteger qmui_badgeInteger;
26+
27+
/// 用字符串设置未读数,nil 表示不显示未读数
28+
@property(nonatomic, copy) NSString *qmui_badgeString;
2629

2730
@property(nonatomic, strong, nullable) UIColor *qmui_badgeBackgroundColor;
2831
@property(nonatomic, strong, nullable) UIColor *qmui_badgeTextColor;
@@ -44,6 +47,7 @@
4447

4548
#pragma mark - UpdatesIndicator
4649

50+
/// 控制红点的显隐
4751
@property(nonatomic, assign) BOOL qmui_shouldShowUpdatesIndicator;
4852
@property(nonatomic, strong, nullable) UIColor *qmui_updatesIndicatorColor;
4953
@property(nonatomic, assign) CGSize qmui_updatesIndicatorSize;

QMUIKit/QMUIComponents/QMUIBadge/UIBarItem+QMUIBadge.m

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ + (void)load {
4646

4747
// 针对非 customView 的 UIBarButtonItem,负责将红点添加上去
4848
ExtendImplementationOfVoidMethodWithSingleArgument([UIBarButtonItem class], @selector(setView:), UIView *, ^(UIBarButtonItem *selfObject, UIView *firstArgv) {
49-
if (selfObject.qmui_badgeValue > 0 && selfObject.qmui_badgeLabel) {
49+
if (selfObject.qmui_badgeString.length && selfObject.qmui_badgeLabel) {
5050
[firstArgv addSubview:selfObject.qmui_badgeLabel];
5151
}
5252
if (selfObject.qmui_shouldShowUpdatesIndicator && selfObject.qmui_updatesIndicatorView) {
@@ -56,7 +56,7 @@ + (void)load {
5656

5757
// 针对 UITabBarItem,负责将红点添加上去
5858
ExtendImplementationOfVoidMethodWithSingleArgument([UITabBarItem class], @selector(setView:), UIView *, ^(UITabBarItem *selfObject, UIView *firstArgv) {
59-
if (selfObject.qmui_badgeValue > 0 && selfObject.qmui_badgeLabel) {
59+
if (selfObject.qmui_badgeString.length && selfObject.qmui_badgeLabel) {
6060
[firstArgv addSubview:selfObject.qmui_badgeLabel];
6161
}
6262
if (selfObject.qmui_shouldShowUpdatesIndicator && selfObject.qmui_updatesIndicatorView) {
@@ -113,10 +113,20 @@ - (void)didInitialize {
113113

114114
#pragma mark - Badge
115115

116-
static char kAssociatedObjectKey_badgeValue;
117-
- (void)setQmui_badgeValue:(NSUInteger)qmui_badgeValue {
118-
objc_setAssociatedObject(self, &kAssociatedObjectKey_badgeValue, @(qmui_badgeValue), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
119-
if (qmui_badgeValue > 0) {
116+
static char kAssociatedObjectKey_badgeInteger;
117+
- (void)setQmui_badgeInteger:(NSUInteger)qmui_badgeInteger {
118+
objc_setAssociatedObject(self, &kAssociatedObjectKey_badgeInteger, @(qmui_badgeInteger), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
119+
self.qmui_badgeString = qmui_badgeInteger > 0 ? [NSString stringWithFormat:@"%@", @(qmui_badgeInteger)] : nil;
120+
}
121+
122+
- (NSUInteger)qmui_badgeInteger {
123+
return [((NSNumber *)objc_getAssociatedObject(self, &kAssociatedObjectKey_badgeInteger)) unsignedIntegerValue];
124+
}
125+
126+
static char kAssociatedObjectKey_badgeString;
127+
- (void)setQmui_badgeString:(NSString *)qmui_badgeString {
128+
objc_setAssociatedObject(self, &kAssociatedObjectKey_badgeString, qmui_badgeString, OBJC_ASSOCIATION_COPY_NONATOMIC);
129+
if (qmui_badgeString.length) {
120130
if (!self.qmui_badgeLabel) {
121131
self.qmui_badgeLabel = [[_QMUIBadgeLabel alloc] init];
122132
self.qmui_badgeLabel.clipsToBounds = YES;
@@ -129,16 +139,16 @@ - (void)setQmui_badgeValue:(NSUInteger)qmui_badgeValue {
129139
self.qmui_badgeLabel.centerOffsetLandscape = self.qmui_badgeCenterOffsetLandscape;
130140
[self.qmui_view addSubview:self.qmui_badgeLabel];
131141
}
132-
self.qmui_badgeLabel.text = [NSString stringWithFormat:@"%@", @(qmui_badgeValue)];
142+
self.qmui_badgeLabel.text = qmui_badgeString;
133143
self.qmui_badgeLabel.hidden = NO;
134144
[self setNeedsUpdateBadgeLabelLayout];
135145
} else {
136146
self.qmui_badgeLabel.hidden = YES;
137147
}
138148
}
139149

140-
- (NSUInteger)qmui_badgeValue {
141-
return [((NSNumber *)objc_getAssociatedObject(self, &kAssociatedObjectKey_badgeValue)) unsignedIntegerValue];
150+
- (NSString *)qmui_badgeString {
151+
return (NSString *)objc_getAssociatedObject(self, &kAssociatedObjectKey_badgeString);
142152
}
143153

144154
static char kAssociatedObjectKey_badgeBackgroundColor;
@@ -225,7 +235,7 @@ - (_QMUIBadgeLabel *)qmui_badgeLabel {
225235
}
226236

227237
- (void)setNeedsUpdateBadgeLabelLayout {
228-
if (self.qmui_badgeValue > 0) {
238+
if (self.qmui_badgeString.length) {
229239
if ([self isKindOfClass:[UIBarButtonItem class]] && ((UIBarButtonItem *)self).customView) {
230240
// 如果是 customView,由于无法重写它的 layoutSubviews,所以认为它目前的 frame 已经是最终的 frame,直接按照当前 frame 来布局即可
231241
[self.qmui_badgeLabel updateLayout];

QMUIKit/QMUIComponents/QMUICellHeightCache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
- (void)invalidateAllHeightCache;
4141

4242
// 给 tableview 和 collectionview 调用的方法
43-
- (void)enumerateAllOrientationsUsingBlock:(void (^)(NSMutableArray *heightsBySection))block;
43+
- (void)enumerateAllOrientationsUsingBlock:(void (^)(NSMutableArray<NSMutableArray<NSNumber *> *> *heightsBySection))block;
4444
- (void)buildSectionsIfNeeded:(NSInteger)targetSection;
4545
- (void)buildCachesAtIndexPathsIfNeeded:(NSArray *)indexPaths;
4646

QMUIKit/QMUIComponents/QMUICellHeightCache.m

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
#import "QMUICore.h"
1212
#import "UIScrollView+QMUI.h"
1313
#import "UIView+QMUI.h"
14+
#import "NSNumber+QMUI.h"
1415

1516
@implementation QMUICellHeightCache {
16-
NSMutableDictionary *_mutableHeightsByKeyForPortrait;
17-
NSMutableDictionary *_mutableHeightsByKeyForLandscape;
17+
NSMutableDictionary<id<NSCopying>, NSNumber *> *_mutableHeightsByKeyForPortrait;
18+
NSMutableDictionary<id<NSCopying>, NSNumber *> *_mutableHeightsByKeyForLandscape;
1819
}
1920

2021
- (instancetype)init {
@@ -26,7 +27,7 @@ - (instancetype)init {
2627
return self;
2728
}
2829

29-
- (NSMutableDictionary *)mutableHeightsByKeyForCurrentOrientation {
30+
- (NSMutableDictionary<id<NSCopying>, NSNumber *> *)mutableHeightsByKeyForCurrentOrientation {
3031
return UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation) ? _mutableHeightsByKeyForPortrait : _mutableHeightsByKeyForLandscape;
3132
}
3233

@@ -40,11 +41,7 @@ - (void)cacheHeight:(CGFloat)height byKey:(id<NSCopying>)key {
4041
}
4142

4243
- (CGFloat)heightForKey:(id<NSCopying>)key {
43-
#if CGFLOAT_IS_DOUBLE
44-
return [[self mutableHeightsByKeyForCurrentOrientation][key] doubleValue];
45-
#else
46-
return [[self mutableHeightsByKeyForCurrentOrientation][key] floatValue];
47-
#endif
44+
return [self mutableHeightsByKeyForCurrentOrientation][key].qmui_CGFloatValue;
4845
}
4946

5047
- (void)invalidateHeightForKey:(id<NSCopying>)key {
@@ -64,8 +61,8 @@ - (NSString *)description {
6461
@end
6562

6663
@implementation QMUICellHeightIndexPathCache {
67-
NSMutableArray *_heightsBySectionForPortrait;
68-
NSMutableArray *_heightsBySectionForLandscape;
64+
NSMutableArray<NSMutableArray<NSNumber *> *> *_heightsBySectionForPortrait;
65+
NSMutableArray<NSMutableArray<NSNumber *> *> *_heightsBySectionForLandscape;
6966
}
7067

7168
- (instancetype)init {
@@ -77,11 +74,11 @@ - (instancetype)init {
7774
return self;
7875
}
7976

80-
- (NSMutableArray *)heightsBySectionForCurrentOrientation {
77+
- (NSMutableArray<NSMutableArray<NSNumber *> *> *)heightsBySectionForCurrentOrientation {
8178
return UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation) ? _heightsBySectionForPortrait : _heightsBySectionForLandscape;
8279
}
8380

84-
- (void)enumerateAllOrientationsUsingBlock:(void (^)(NSMutableArray *heightsBySection))block {
81+
- (void)enumerateAllOrientationsUsingBlock:(void (^)(NSMutableArray<NSMutableArray<NSNumber *> *> *heightsBySection))block {
8582
if (block) {
8683
block(_heightsBySectionForPortrait);
8784
block(_heightsBySectionForLandscape);
@@ -102,36 +99,31 @@ - (void)cacheHeight:(CGFloat)height byIndexPath:(NSIndexPath *)indexPath {
10299

103100
- (CGFloat)heightForIndexPath:(NSIndexPath *)indexPath {
104101
[self buildCachesAtIndexPathsIfNeeded:@[indexPath]];
105-
NSNumber *number = self.heightsBySectionForCurrentOrientation[indexPath.section][indexPath.row];
106-
#if CGFLOAT_IS_DOUBLE
107-
return number.doubleValue;
108-
#else
109-
return number.floatValue;
110-
#endif
102+
return self.heightsBySectionForCurrentOrientation[indexPath.section][indexPath.row].qmui_CGFloatValue;
111103
}
112104

113105
- (void)invalidateHeightAtIndexPath:(NSIndexPath *)indexPath {
114106
[self buildCachesAtIndexPathsIfNeeded:@[indexPath]];
115-
[self enumerateAllOrientationsUsingBlock:^(NSMutableArray *heightsBySection) {
107+
[self enumerateAllOrientationsUsingBlock:^(NSMutableArray<NSMutableArray<NSNumber *> *> *heightsBySection) {
116108
heightsBySection[indexPath.section][indexPath.row] = @-1;
117109
}];
118110
}
119111

120112
- (void)invalidateAllHeightCache {
121-
[self enumerateAllOrientationsUsingBlock:^(NSMutableArray *heightsBySection) {
113+
[self enumerateAllOrientationsUsingBlock:^(NSMutableArray<NSMutableArray<NSNumber *> *> *heightsBySection) {
122114
[heightsBySection removeAllObjects];
123115
}];
124116
}
125117

126-
- (void)buildCachesAtIndexPathsIfNeeded:(NSArray *)indexPaths {
118+
- (void)buildCachesAtIndexPathsIfNeeded:(NSArray<NSIndexPath *> *)indexPaths {
127119
[indexPaths enumerateObjectsUsingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) {
128120
[self buildSectionsIfNeeded:indexPath.section];
129121
[self buildRowsIfNeeded:indexPath.row inExistSection:indexPath.section];
130122
}];
131123
}
132124

133125
- (void)buildSectionsIfNeeded:(NSInteger)targetSection {
134-
[self enumerateAllOrientationsUsingBlock:^(NSMutableArray *heightsBySection) {
126+
[self enumerateAllOrientationsUsingBlock:^(NSMutableArray<NSMutableArray<NSNumber *> *> *heightsBySection) {
135127
for (NSInteger section = 0; section <= targetSection; ++section) {
136128
if (section >= heightsBySection.count) {
137129
heightsBySection[section] = [NSMutableArray array];
@@ -141,7 +133,7 @@ - (void)buildSectionsIfNeeded:(NSInteger)targetSection {
141133
}
142134

143135
- (void)buildRowsIfNeeded:(NSInteger)targetRow inExistSection:(NSInteger)section {
144-
[self enumerateAllOrientationsUsingBlock:^(NSMutableArray *heightsBySection) {
136+
[self enumerateAllOrientationsUsingBlock:^(NSMutableArray<NSMutableArray<NSNumber *> *> *heightsBySection) {
145137
NSMutableArray *heightsByRow = heightsBySection[section];
146138
for (NSInteger row = 0; row <= targetRow; ++row) {
147139
if (row >= heightsByRow.count) {

QMUIKit/QMUIComponents/QMUICellHeightKeyCache/UITableView+QMUICellHeightKeyCache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
* 1. 将 tableView.qmui_cacheCellHeightByKeyAutomatically = YES
1717
* 2. 实现 tableView 的 delegate 方法 qmui_tableView:cacheKeyForRowAtIndexPath: 返回一个 key。建议 key 由所有可能影响高度的字段拼起来,这样当数据发生变化时不需要手动更新缓存。
1818
*
19-
* @note 注意这里的高度缓存仅适合于使用 self-sizing 机制的 tableView(也即 tableView.rowHeight = UITableViewAutomaticDimension),QMUICellHeightKeyCache 会自动在 willDisplayCell 里将 cell 的当前高度缓存起来,然后在 heightForRow 里从缓存中读取高度后使用。而如果你的 tableView 并没有使用 self-sizing 机制(也即自己重写了 heightForRow),则请勿使用本控件的功能。
19+
* @note 注意这里的高度缓存仅适合于使用 self-sizing 机制的 tableView(也即 tableView.rowHeight = UITableViewAutomaticDimension),QMUICellHeightKeyCache 会自动在 willDisplayCell 里将 cell 的当前高度缓存起来,然后在 heightForRow 里从缓存中读取高度后使用。
20+
* @note 如果 tableView.delegate 指向的类既想使用 QMUICellHeightKeyCache 的功能,又需要在 tableView:heightForRowAtIndexPath: 里写业务逻辑,则可通过 tableView:heightForRowAtIndexPath: 返回 -1 来使用 QMUICellHeightKeyCache 的计算结果,返回大于等于 0 的值将不会触发 QMUICellHeightKeyCache 的计算,具体请看 QMUI Demo。
2021
*
2122
* @note 在 UITableView 的宽度和 contentInset 发生变化时(例如横竖屏旋转、iPad 分屏),高度缓存会自动刷新,所以无需为这种情况做保护。
2223
*/

0 commit comments

Comments
 (0)