Skip to content

Commit

Permalink
2.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLice committed Oct 31, 2018
1 parent a2a59a8 commit a0e2811
Show file tree
Hide file tree
Showing 36 changed files with 984 additions and 154 deletions.
7 changes: 6 additions & 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.8.1"
s.version = "2.9.0"
s.summary = "致力于提高项目 UI 开发效率的解决方案"
s.description = <<-DESC
QMUI iOS 是一个致力于提高项目 UI 开发效率的解决方案,其设计目的是用于辅助快速搭建一个具备基本设计还原效果的 iOS 项目,同时利用自身提供的丰富控件及兼容处理, 让开发者能专注于业务需求而无需耗费精力在基础代码的设计上。不管是新项目的创建,或是已有项目的维护,均可使开发效率和项目质量得到大幅度提升。
Expand Down Expand Up @@ -219,6 +219,11 @@ Pod::Spec.new do |s|
sss.dependency 'QMUIKit/QMUIComponents/QMUIButton'
sss.dependency 'QMUIKit/QMUIComponents/QMUIPopupContainerView'
end

ss.subspec 'QMUIScrollAnimator' do |sss|
sss.source_files = 'QMUIKit/QMUIComponents/QMUIScrollAnimator/*.{h,m}'
sss.dependency 'QMUIKit/QMUIComponents/QMUIMultipleDelegates'
end

ss.subspec 'QMUIEmotionInputManager' do |sss|
sss.source_files = 'QMUIKit/QMUIComponents/QMUIEmotionInputManager.{h,m}'
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.8.1</string>
<string>2.9.0</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 @@ -15,6 +15,7 @@
#import "UINavigationBar+Transition.h"
#import "QMUICommonViewController.h"
#import "QMUINavigationTitleView.h"
#import "UINavigationBar+QMUI.h"

@interface _QMUITransitionNavigationBar : UINavigationBar

Expand All @@ -26,8 +27,7 @@ - (void)layoutSubviews {
[super layoutSubviews];
if (@available(iOS 11, *)) {
// iOS 11 以前,自己 init 的 navigationBar,它的 backgroundView 默认会一直保持与 navigationBar 的高度相等,但 iOS 11 Beta 1-5 里,自己 init 的 navigationBar.backgroundView.height 默认一直是 44,所以才加上这个兼容
UIView *backgroundView = [self valueForKey:@"backgroundView"];
backgroundView.frame = self.bounds;
self.qmui_backgroundView.frame = self.bounds;
}
}

Expand Down Expand Up @@ -83,6 +83,7 @@ - (void)NavigationBarTransition_viewWillAppear:(BOOL)animated {

- (void)NavigationBarTransition_viewDidAppear:(BOOL)animated {
if (self.transitionNavigationBar) {

[UIViewController replaceStyleForNavigationBar:self.transitionNavigationBar withNavigationBar:self.navigationController.navigationBar];
[self removeTransitionNavigationBar];
self.lockTransitionNavigationBar = YES;
Expand All @@ -91,15 +92,19 @@ - (void)NavigationBarTransition_viewDidAppear:(BOOL)animated {
[transitionCoordinator containerView].backgroundColor = self.originContainerViewBackgroundColor;
self.view.clipsToBounds = self.originClipsToBounds;
}
self.prefersNavigationBarBackgroundViewHidden = NO;

if (self.navigationController.viewControllers.count && [self.navigationController.viewControllers containsObject:self]) {
// 防止一些 childViewController 走到这里
self.prefersNavigationBarBackgroundViewHidden = NO;
}

[self NavigationBarTransition_viewDidAppear:animated];
}

- (void)NavigationBarTransition_viewDidDisappear:(BOOL)animated {
if (self.transitionNavigationBar) {
[self removeTransitionNavigationBar];
self.lockTransitionNavigationBar = NO;

self.view.clipsToBounds = self.originClipsToBounds;
}
[self NavigationBarTransition_viewDidDisappear:animated];
Expand All @@ -118,8 +123,7 @@ - (void)NavigationBarTransition_viewWillLayoutSubviews {

BOOL shouldCustomNavigationBarTransition = NO;

if (!self.transitionNavigationBar) {

if (!self.transitionNavigationBar || !self.transitionNavigationBar.superview) {
if (isPushingViewContrller) {
if ([toViewController canCustomNavigationBarTransitionWhenPushAppearing] ||
[fromViewController canCustomNavigationBarTransitionWhenPushDisappearing]) {
Expand All @@ -131,7 +135,6 @@ - (void)NavigationBarTransition_viewWillLayoutSubviews {
shouldCustomNavigationBarTransition = YES;
}
}

if (shouldCustomNavigationBarTransition) {
if (self.navigationController.navigationBar.translucent) {
// 如果原生bar是半透明的,需要给containerView加个背景色,否则有可能会看到下面的默认黑色背景色
Expand Down Expand Up @@ -165,18 +168,22 @@ - (void)addTransitionNavigationBarIfNeeded {
if (customBar.barStyle != originBar.barStyle) {
customBar.barStyle = originBar.barStyle;
}

if (customBar.translucent != originBar.translucent) {
customBar.translucent = originBar.translucent;
}

if (![customBar.barTintColor isEqual:originBar.barTintColor]) {
customBar.barTintColor = originBar.barTintColor;
}

UIImage *backgroundImage = [originBar backgroundImageForBarMetrics:UIBarMetricsDefault];
if (backgroundImage && CGSizeEqualToSize(backgroundImage.size, CGSizeZero)) {
if (backgroundImage && backgroundImage.size.width <= 0 && backgroundImage.size.height <= 0) {
// 假设这里的图片时通过`[UIImage new]`这种形式创建的,那么会navBar会奇怪地显示为系统默认navBar的样式。不知道为什么 navController 设置自己的 navBar 为 [UIImage new] 却没事,所以这里做个保护。
backgroundImage = [UIImage qmui_imageWithColor:UIColorClear];
}
[customBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];

[customBar setShadowImage:originBar.shadowImage];

self.transitionNavigationBar = customBar;
Expand All @@ -188,18 +195,17 @@ - (void)addTransitionNavigationBarIfNeeded {
}

- (void)removeTransitionNavigationBar {
if (!self.transitionNavigationBar) {
if (!self.transitionNavigationBar || !self.transitionNavigationBar.superview) {
return;
}
[self.transitionNavigationBar removeFromSuperview];
self.transitionNavigationBar = nil;
}

- (void)resizeTransitionNavigationBarFrame {
if (!self.view.window) {
return;
}
UIView *backgroundView = [self.navigationController.navigationBar valueForKey:@"backgroundView"];
UIView *backgroundView = self.navigationController.navigationBar.qmui_backgroundView;
CGRect rect = [backgroundView.superview convertRect:backgroundView.frame toView:self.view];
self.transitionNavigationBar.frame = rect;
}
Expand Down Expand Up @@ -242,37 +248,36 @@ - (void)renderNavigationStyleInViewController:(UIViewController *)viewController
}
}

// 导航栏的背景色
if ([vc respondsToSelector:@selector(navigationBarBarTintColor)]) {
UIColor *barTintColor = [vc navigationBarBarTintColor];
viewController.navigationController.navigationBar.barTintColor = barTintColor;
} else {
viewController.navigationController.navigationBar.barTintColor = NavBarBarTintColor;
}

// 导航栏的背景
if ([vc respondsToSelector:@selector(navigationBarBackgroundImage)]) {
UIImage *backgroundImage = [vc navigationBarBackgroundImage];
[viewController.navigationController.navigationBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
} else {
UIImage *backgroundImage = NavBarBackgroundImage;
if (backgroundImage) {
[viewController.navigationController.navigationBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
}
[viewController.navigationController.navigationBar setBackgroundImage:NavBarBackgroundImage forBarMetrics:UIBarMetricsDefault];
}

// 导航栏底部的分隔线
if ([vc respondsToSelector:@selector(navigationBarShadowImage)]) {
UIImage *shadowImage = [vc navigationBarShadowImage];
[viewController.navigationController.navigationBar setShadowImage:shadowImage];
} else {
UIImage *shadowImage = NavBarShadowImage;
if (shadowImage) {
[viewController.navigationController.navigationBar setShadowImage:shadowImage];
}
[viewController.navigationController.navigationBar setShadowImage:NavBarShadowImage];
}

// 导航栏上控件的主题色
if ([vc respondsToSelector:@selector(navigationBarTintColor)]) {
UIColor *tintColor = [vc navigationBarTintColor];
viewController.navigationController.navigationBar.tintColor = tintColor;
} else {
UIColor *tintColor = NavBarTintColor;
if (tintColor) {
viewController.navigationController.navigationBar.tintColor = tintColor;
}
viewController.navigationController.navigationBar.tintColor = NavBarTintColor;
}

// 导航栏title的颜色
Expand All @@ -284,13 +289,10 @@ - (void)renderNavigationStyleInViewController:(UIViewController *)viewController
// TODO: molice 对 UIViewController 也支持修改 title 颜色
}
} else {
UIColor *tintColor = NavBarTitleColor;
if (tintColor) {
if ([vc isKindOfClass:[QMUICommonViewController class]]) {
((QMUICommonViewController *)vc).titleView.tintColor = tintColor;
} else {
// TODO: molice 对 UIViewController 也支持修改 title 颜色
}
if ([vc isKindOfClass:[QMUICommonViewController class]]) {
((QMUICommonViewController *)vc).titleView.tintColor = NavBarTitleColor;
} else {
// TODO: molice 对 UIViewController 也支持修改 title 颜色
}
}
}
Expand All @@ -299,8 +301,8 @@ - (void)renderNavigationStyleInViewController:(UIViewController *)viewController
+ (void)replaceStyleForNavigationBar:(UINavigationBar *)navbarA withNavigationBar:(UINavigationBar *)navbarB {
navbarB.barStyle = navbarA.barStyle;
navbarB.barTintColor = navbarA.barTintColor;
[navbarB setBackgroundImage:[navbarA backgroundImageForBarMetrics:UIBarMetricsDefault] forBarMetrics:UIBarMetricsDefault];
[navbarB setShadowImage:navbarA.shadowImage];
[navbarB setBackgroundImage:[navbarA backgroundImageForBarMetrics:UIBarMetricsDefault] forBarMetrics:UIBarMetricsDefault];
}

// 该 viewController 是否实现自定义 navBar 动画的协议
Expand Down Expand Up @@ -456,7 +458,12 @@ - (BOOL)prefersNavigationBarBackgroundViewHidden {
}

- (void)setPrefersNavigationBarBackgroundViewHidden:(BOOL)prefersNavigationBarBackgroundViewHidden {
[[self.navigationController.navigationBar valueForKey:@"backgroundView"] setHidden:prefersNavigationBarBackgroundViewHidden];
// 从某个版本开始,发现从有 navBar 的界面返回无 navBar 的界面,backgroundView 会跑出来,发现是被系统重新设置了显示,所以改用其他的方法来隐藏 backgroundView,就是 mask。
if (prefersNavigationBarBackgroundViewHidden) {
self.navigationController.navigationBar.qmui_backgroundView.layer.mask = [CALayer layer];
} else {
self.navigationController.navigationBar.qmui_backgroundView.layer.mask = nil;
}
objc_setAssociatedObject(self, @selector(prefersNavigationBarBackgroundViewHidden), [[NSNumber alloc] initWithBool:prefersNavigationBarBackgroundViewHidden], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

Expand Down
6 changes: 3 additions & 3 deletions QMUIKit/QMUIComponents/QMUIAlertController.m
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ - (void)customModalPresentationControllerAnimation {
}
}];
} else if (self.preferredStyle == QMUIAlertControllerStyleActionSheet) {
weakSelf.containerView.layer.transform = CATransform3DMakeTranslation(0, CGRectGetHeight(weakSelf.containerView.bounds), 0);
weakSelf.containerView.layer.transform = CATransform3DMakeTranslation(0, CGRectGetHeight(weakSelf.view.bounds) - CGRectGetMinY(weakSelf.containerView.frame), 0);
[UIView animateWithDuration:0.25f delay:0 options:QMUIViewAnimationOptionsCurveOut animations:^{
weakSelf.maskView.alpha = 1;
weakSelf.containerView.layer.transform = CATransform3DIdentity;
Expand All @@ -869,7 +869,7 @@ - (void)customModalPresentationControllerAnimation {
} else if (self.preferredStyle == QMUIAlertControllerStyleActionSheet) {
[UIView animateWithDuration:0.25f delay:0 options:QMUIViewAnimationOptionsCurveOut animations:^{
weakSelf.maskView.alpha = 0;
weakSelf.containerView.layer.transform = CATransform3DMakeTranslation(0, CGRectGetHeight(weakSelf.containerView.bounds), 0);
weakSelf.containerView.layer.transform = CATransform3DMakeTranslation(0, CGRectGetHeight(weakSelf.view.bounds) - CGRectGetMinY(weakSelf.containerView.frame), 0);
} completion:^(BOOL finished) {
if (completion) {
completion(finished);
Expand Down Expand Up @@ -955,7 +955,7 @@ - (void)hideWithAnimated:(BOOL)animated completion:(void (^)(void))completion {
if (self.preferredStyle == QMUIAlertControllerStyleAlert) {
weakSelf.containerView.alpha = 0;
} else {
weakSelf.containerView.layer.transform = CATransform3DMakeTranslation(0, CGRectGetHeight(weakSelf.containerView.bounds), 0);
weakSelf.containerView.layer.transform = CATransform3DMakeTranslation(0, CGRectGetHeight(weakSelf.view.bounds) - CGRectGetMinY(weakSelf.containerView.frame), 0);
}
if ([weakSelf.delegate respondsToSelector:@selector(didHideAlertController:)]) {
[weakSelf.delegate didHideAlertController:weakSelf];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#import "UIView+QMUI.h"
#import "UIScrollView+QMUI.h"
#import "QMUITableViewProtocols.h"
#import <objc/runtime.h>
#import "QMUIMultipleDelegates.h"

@interface UITableView ()

Expand Down Expand Up @@ -51,7 +51,10 @@ - (void)setQmui_cacheCellHeightByKeyAutomatically:(BOOL)qmui_cacheCellHeightByKe
self.delegate = self.delegate;
} else {
id <QMUITableViewDelegate> tempDelegate = (id<QMUITableViewDelegate>)self.delegate;
self.delegate = nil;
// 如果正在使用 QMUIMultipleDelegate,那么它内部会自己先设置为 nil,因此这里不需要额外再弄一次。而且如果这里设置为 nil,反而会使 QMUIMultipleDelegate 内的所有 delegate 都被清空
if (![tempDelegate isKindOfClass:[QMUIMultipleDelegates class]]) {
self.delegate = nil;
}
self.delegate = tempDelegate;
}
}
Expand Down Expand Up @@ -124,14 +127,27 @@ - (void)replaceMethodForDelegateIfNeeded:(id<QMUITableViewDelegate>)delegate {
if (!qmui_methodsReplacedClasses) {
qmui_methodsReplacedClasses = [NSMutableSet set];
}
if ([qmui_methodsReplacedClasses containsObject:NSStringFromClass(delegate.class)]) {
return;
}
[qmui_methodsReplacedClasses addObject:NSStringFromClass(delegate.class)];

[self handleWillDisplayCellMethodForDelegate:delegate];
[self handleHeightForRowMethodForDelegate:delegate];
void (^addSelectorBlock)(id<QMUITableViewDelegate>) = ^void(id<QMUITableViewDelegate> aDelegate) {
if ([qmui_methodsReplacedClasses containsObject:NSStringFromClass(aDelegate.class)]) {
return;
}
[qmui_methodsReplacedClasses addObject:NSStringFromClass(aDelegate.class)];

[self handleWillDisplayCellMethodForDelegate:aDelegate];
[self handleHeightForRowMethodForDelegate:aDelegate];
};

if ([delegate isKindOfClass:[QMUIMultipleDelegates class]]) {
NSPointerArray *delegates = [((QMUIMultipleDelegates *)delegate).delegates copy];
for (id d in delegates) {
if ([d conformsToProtocol:@protocol(QMUITableViewDelegate)]) {
addSelectorBlock((id<QMUITableViewDelegate>)d);
}
}
} else {
addSelectorBlock((id<QMUITableViewDelegate>)delegate);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "QMUICore.h"
#import "QMUICellSizeKeyCache.h"
#import "UIScrollView+QMUI.h"
#import <objc/runtime.h>
#import "QMUIMultipleDelegates.h"

//@interface UICollectionViewCell (QMUICellSizeKeyCache)
//
Expand Down Expand Up @@ -178,10 +178,23 @@ - (void)replaceMethodForDelegateIfNeeded:(id<UICollectionViewDelegate>)delegate
if (!qmui_methodsReplacedClasses) {
qmui_methodsReplacedClasses = [NSMutableSet set];
}
if ([qmui_methodsReplacedClasses containsObject:NSStringFromClass(delegate.class)]) {
return;
void (^addSelectorBlock)(id<UICollectionViewDelegate>) = ^void(id<UICollectionViewDelegate> aDelegate) {
if ([qmui_methodsReplacedClasses containsObject:NSStringFromClass(aDelegate.class)]) {
return;
}
[qmui_methodsReplacedClasses addObject:NSStringFromClass(aDelegate.class)];
};

if ([delegate isKindOfClass:[QMUIMultipleDelegates class]]) {
NSPointerArray *delegates = [((QMUIMultipleDelegates *)delegate).delegates copy];
for (id d in delegates) {
if ([d conformsToProtocol:@protocol(UICollectionViewDelegate)]) {
addSelectorBlock((id<UICollectionViewDelegate>)d);
}
}
} else {
addSelectorBlock((id<UICollectionViewDelegate>)delegate);
}
[qmui_methodsReplacedClasses addObject:NSStringFromClass(delegate.class)];
}
}

Expand Down
4 changes: 0 additions & 4 deletions QMUIKit/QMUIComponents/QMUIDialogViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ - (void)didInitialize {
self.modalPresentationViewController.modal = YES;
}

- (void)dealloc {
NSLog(@"");
}

- (void)setCornerRadius:(CGFloat)cornerRadius {
_cornerRadius = cornerRadius;
if ([self isViewLoaded]) {
Expand Down
11 changes: 8 additions & 3 deletions QMUIKit/QMUIComponents/QMUIModalPresentationViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,14 @@ - (void)didInitialize {
self.maximumContentViewWidth = appearance.maximumContentViewWidth;
self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
self.modalPresentationStyle = UIModalPresentationCustom;
self.supportedOrientationMask = SupportedOrientationMask;

// 这一段是给以 present 方式显示的浮层用的,其他方式显示的浮层,会在 supportedInterfaceOrientations 里实时获取支持的设备方向
UIViewController *visibleViewController = [QMUIHelper visibleViewController];
if (visibleViewController) {
self.supportedOrientationMask = visibleViewController.supportedInterfaceOrientations;
} else {
self.supportedOrientationMask = SupportedOrientationMask;
}

if (self != appearance) {
self.keyboardManager = [[QMUIKeyboardManager alloc] initWithDelegate:self];
Expand Down Expand Up @@ -142,8 +149,6 @@ - (void)viewDidLayoutSubviews {
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

self.supportedOrientationMask = [QMUIHelper visibleViewController].supportedInterfaceOrientations;

if (self.shownInWindowMode) {
// 只有使用showWithAnimated:completion:显示出来的浮层,才需要修改之前就记住的animated的值
animated = self.appearAnimated;
Expand Down
Loading

0 comments on commit a0e2811

Please sign in to comment.