Skip to content

Commit

Permalink
2.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLice committed Jun 12, 2018
1 parent d87cf14 commit 33afad6
Show file tree
Hide file tree
Showing 29 changed files with 230 additions and 323 deletions.
2 changes: 1 addition & 1 deletion QMUIKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "QMUIKit"
s.version = "2.7.0"
s.version = "2.7.1"
s.summary = "致力于提高项目 UI 开发效率的解决方案"
s.description = <<-DESC
QMUI iOS 是一个致力于提高项目 UI 开发效率的解决方案,其设计目的是用于辅助快速搭建一个具备基本设计还原效果的 iOS 项目,同时利用自身提供的丰富控件及兼容处理, 让开发者能专注于业务需求而无需耗费精力在基础代码的设计上。不管是新项目的创建,或是已有项目的维护,均可使开发效率和项目质量得到大幅度提升。
Expand Down
2 changes: 1 addition & 1 deletion QMUIKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.7.0</string>
<string>2.7.1</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ - (void)viewDidLayoutSubviews {
}
}

- (BOOL)prefersStatusBarHidden {
return YES;
}

- (void)setToolBarBackgroundColor:(UIColor *)toolBarBackgroundColor {
_toolBarBackgroundColor = toolBarBackgroundColor;
self.topToolBarView.backgroundColor = self.toolBarBackgroundColor;
Expand Down
8 changes: 6 additions & 2 deletions QMUIKit/QMUIComponents/QMUIBadge/UIBarItem+QMUIBadge.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@

#pragma mark - Badge

/// 设置未读数,0 则隐藏未读数
@property(nonatomic, assign) NSUInteger qmui_badgeValue;
/// 用数字设置未读数,0表示不显示未读数
@property(nonatomic, assign) NSUInteger qmui_badgeInteger;

/// 用字符串设置未读数,nil 表示不显示未读数
@property(nonatomic, copy) NSString *qmui_badgeString;

@property(nonatomic, strong, nullable) UIColor *qmui_badgeBackgroundColor;
@property(nonatomic, strong, nullable) UIColor *qmui_badgeTextColor;
Expand All @@ -44,6 +47,7 @@

#pragma mark - UpdatesIndicator

/// 控制红点的显隐
@property(nonatomic, assign) BOOL qmui_shouldShowUpdatesIndicator;
@property(nonatomic, strong, nullable) UIColor *qmui_updatesIndicatorColor;
@property(nonatomic, assign) CGSize qmui_updatesIndicatorSize;
Expand Down
30 changes: 20 additions & 10 deletions QMUIKit/QMUIComponents/QMUIBadge/UIBarItem+QMUIBadge.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ + (void)load {

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

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

#pragma mark - Badge

static char kAssociatedObjectKey_badgeValue;
- (void)setQmui_badgeValue:(NSUInteger)qmui_badgeValue {
objc_setAssociatedObject(self, &kAssociatedObjectKey_badgeValue, @(qmui_badgeValue), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
if (qmui_badgeValue > 0) {
static char kAssociatedObjectKey_badgeInteger;
- (void)setQmui_badgeInteger:(NSUInteger)qmui_badgeInteger {
objc_setAssociatedObject(self, &kAssociatedObjectKey_badgeInteger, @(qmui_badgeInteger), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
self.qmui_badgeString = qmui_badgeInteger > 0 ? [NSString stringWithFormat:@"%@", @(qmui_badgeInteger)] : nil;
}

- (NSUInteger)qmui_badgeInteger {
return [((NSNumber *)objc_getAssociatedObject(self, &kAssociatedObjectKey_badgeInteger)) unsignedIntegerValue];
}

static char kAssociatedObjectKey_badgeString;
- (void)setQmui_badgeString:(NSString *)qmui_badgeString {
objc_setAssociatedObject(self, &kAssociatedObjectKey_badgeString, qmui_badgeString, OBJC_ASSOCIATION_COPY_NONATOMIC);
if (qmui_badgeString.length) {
if (!self.qmui_badgeLabel) {
self.qmui_badgeLabel = [[_QMUIBadgeLabel alloc] init];
self.qmui_badgeLabel.clipsToBounds = YES;
Expand All @@ -129,16 +139,16 @@ - (void)setQmui_badgeValue:(NSUInteger)qmui_badgeValue {
self.qmui_badgeLabel.centerOffsetLandscape = self.qmui_badgeCenterOffsetLandscape;
[self.qmui_view addSubview:self.qmui_badgeLabel];
}
self.qmui_badgeLabel.text = [NSString stringWithFormat:@"%@", @(qmui_badgeValue)];
self.qmui_badgeLabel.text = qmui_badgeString;
self.qmui_badgeLabel.hidden = NO;
[self setNeedsUpdateBadgeLabelLayout];
} else {
self.qmui_badgeLabel.hidden = YES;
}
}

- (NSUInteger)qmui_badgeValue {
return [((NSNumber *)objc_getAssociatedObject(self, &kAssociatedObjectKey_badgeValue)) unsignedIntegerValue];
- (NSString *)qmui_badgeString {
return (NSString *)objc_getAssociatedObject(self, &kAssociatedObjectKey_badgeString);
}

static char kAssociatedObjectKey_badgeBackgroundColor;
Expand Down Expand Up @@ -225,7 +235,7 @@ - (_QMUIBadgeLabel *)qmui_badgeLabel {
}

- (void)setNeedsUpdateBadgeLabelLayout {
if (self.qmui_badgeValue > 0) {
if (self.qmui_badgeString.length) {
if ([self isKindOfClass:[UIBarButtonItem class]] && ((UIBarButtonItem *)self).customView) {
// 如果是 customView,由于无法重写它的 layoutSubviews,所以认为它目前的 frame 已经是最终的 frame,直接按照当前 frame 来布局即可
[self.qmui_badgeLabel updateLayout];
Expand Down
2 changes: 1 addition & 1 deletion QMUIKit/QMUIComponents/QMUICellHeightCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
- (void)invalidateAllHeightCache;

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

Expand Down
38 changes: 15 additions & 23 deletions QMUIKit/QMUIComponents/QMUICellHeightCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
#import "QMUICore.h"
#import "UIScrollView+QMUI.h"
#import "UIView+QMUI.h"
#import "NSNumber+QMUI.h"

@implementation QMUICellHeightCache {
NSMutableDictionary *_mutableHeightsByKeyForPortrait;
NSMutableDictionary *_mutableHeightsByKeyForLandscape;
NSMutableDictionary<id<NSCopying>, NSNumber *> *_mutableHeightsByKeyForPortrait;
NSMutableDictionary<id<NSCopying>, NSNumber *> *_mutableHeightsByKeyForLandscape;
}

- (instancetype)init {
Expand All @@ -26,7 +27,7 @@ - (instancetype)init {
return self;
}

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

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

- (CGFloat)heightForKey:(id<NSCopying>)key {
#if CGFLOAT_IS_DOUBLE
return [[self mutableHeightsByKeyForCurrentOrientation][key] doubleValue];
#else
return [[self mutableHeightsByKeyForCurrentOrientation][key] floatValue];
#endif
return [self mutableHeightsByKeyForCurrentOrientation][key].qmui_CGFloatValue;
}

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

@implementation QMUICellHeightIndexPathCache {
NSMutableArray *_heightsBySectionForPortrait;
NSMutableArray *_heightsBySectionForLandscape;
NSMutableArray<NSMutableArray<NSNumber *> *> *_heightsBySectionForPortrait;
NSMutableArray<NSMutableArray<NSNumber *> *> *_heightsBySectionForLandscape;
}

- (instancetype)init {
Expand All @@ -77,11 +74,11 @@ - (instancetype)init {
return self;
}

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

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

- (CGFloat)heightForIndexPath:(NSIndexPath *)indexPath {
[self buildCachesAtIndexPathsIfNeeded:@[indexPath]];
NSNumber *number = self.heightsBySectionForCurrentOrientation[indexPath.section][indexPath.row];
#if CGFLOAT_IS_DOUBLE
return number.doubleValue;
#else
return number.floatValue;
#endif
return self.heightsBySectionForCurrentOrientation[indexPath.section][indexPath.row].qmui_CGFloatValue;
}

- (void)invalidateHeightAtIndexPath:(NSIndexPath *)indexPath {
[self buildCachesAtIndexPathsIfNeeded:@[indexPath]];
[self enumerateAllOrientationsUsingBlock:^(NSMutableArray *heightsBySection) {
[self enumerateAllOrientationsUsingBlock:^(NSMutableArray<NSMutableArray<NSNumber *> *> *heightsBySection) {
heightsBySection[indexPath.section][indexPath.row] = @-1;
}];
}

- (void)invalidateAllHeightCache {
[self enumerateAllOrientationsUsingBlock:^(NSMutableArray *heightsBySection) {
[self enumerateAllOrientationsUsingBlock:^(NSMutableArray<NSMutableArray<NSNumber *> *> *heightsBySection) {
[heightsBySection removeAllObjects];
}];
}

- (void)buildCachesAtIndexPathsIfNeeded:(NSArray *)indexPaths {
- (void)buildCachesAtIndexPathsIfNeeded:(NSArray<NSIndexPath *> *)indexPaths {
[indexPaths enumerateObjectsUsingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) {
[self buildSectionsIfNeeded:indexPath.section];
[self buildRowsIfNeeded:indexPath.row inExistSection:indexPath.section];
}];
}

- (void)buildSectionsIfNeeded:(NSInteger)targetSection {
[self enumerateAllOrientationsUsingBlock:^(NSMutableArray *heightsBySection) {
[self enumerateAllOrientationsUsingBlock:^(NSMutableArray<NSMutableArray<NSNumber *> *> *heightsBySection) {
for (NSInteger section = 0; section <= targetSection; ++section) {
if (section >= heightsBySection.count) {
heightsBySection[section] = [NSMutableArray array];
Expand All @@ -141,7 +133,7 @@ - (void)buildSectionsIfNeeded:(NSInteger)targetSection {
}

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

0 comments on commit 33afad6

Please sign in to comment.