Skip to content

4.0.0

Compare
Choose a tag to compare
@MoLice MoLice released this 27 Sep 14:00
· 137 commits to master since this release

重要说明

QMUI 4.0.0 更新内容主要是兼容 iOS 13,如你正使用的 QMUI 版本低于 4.0.0-beta,建议即刻起升级到 4.0.0,旧版本的 QMUI 在 iOS 13 上产生的任何问题我们均不再处理。

与 4.0.0-beta 的关系

4.0.0 和 4.0.0-beta 是两个独立的正式版本,由于 Apple 从发布 iOS 13 beta1 到发布 iOS 13 正式版,期间耗时较长,因此 QMUI 对 iOS 13 的兼容也分成两个版本发布,对于业务项目,理想的升级路径是先升级到 4.0.0-beta,再升级到 4.0.0,因此 4.0.0 的 Release Note 是针对从 4.0.0-beta 升级上来的项目而撰写的,如果你直接从 3.x.x 升级到 4.0.0,需要同时参照 4.0.0-beta 和 4.0.0 两份 Release Note(这个道理就跟从 3.1.9 跳过 3.2.0 直接升级到 3.2.1 一样,也是需要参考两份 Release Note 进行操作)。

QMUITheme 的变化

QMUITheme 组件增加 QMUIThemeManagerCenter,用于支持同一个项目里存在多个维度的主题。以“微信读书”为例,整个 App 拥有 light/dark 两套主题,生效于所有界面,而阅读器自身又拥有 4 套主题(白/黄/绿/黑),通过 QMUIThemeManagerCenter 才能让这两个维度的主题共存在同一个项目里,保证阅读器的 color/image/effect 只响应阅读器的 4 套主题,不受外面 light/dark 切换的影响。相应地,之前升级到 4.0.0-beta 并使用了 QMUITheme 的项目也需要跟着调整,具体请看 如何适配新版

基于此调整,UIColor (QMUITheme)、UIImage (QMUITheme)、UIVisualEffect (QMUITheme) 均增加了新的 init 方法来初始化不同维度主题下的动态对象,没有多维度主题需求的项目请继续使用之前的方式创建动态对象。

@interface UIColor (QMUITheme)
+ (UIColor *)qmui_colorWithThemeManagerName:(__kindof NSObject<NSCopying> *)name provider:(UIColor *(^)(__kindof QMUIThemeManager *manager, __kindof NSObject<NSCopying> * _Nullable identifier, __kindof NSObject * _Nullable theme))provider;
@end

@interface UIImage (QMUITheme)
+ (UIImage *)qmui_imageWithThemeManagerName:(__kindof NSObject<NSCopying> *)name provider:(UIImage *(^)(__kindof QMUIThemeManager *manager, __kindof NSObject<NSCopying> * _Nullable identifier, __kindof NSObject * _Nullable theme))provider;
@end

@interface UIVisualEffect (QMUITheme)
+ (UIVisualEffect *)qmui_effectWithThemeManagerName:(__kindof NSObject<NSCopying> *)name provider:(UIVisualEffect *(^)(__kindof QMUIThemeManager *manager, __kindof NSObject<NSCopying> * _Nullable identifier, __kindof NSObject * _Nullable theme))provider;
@end

-[UIView (QMUITheme) qmui_registerThemeColorProperties:] 方法之前只支持注册 UIColor 类型的 property,现在它支持所有 NSObject 类型的 property了。

CAShapeLayerfillColorstrokeColor,以及 CAGradientLayercolors,都支持 QMUIThemeColor 了。

对于 QMUIThemeImage,之前我们要求在 provider block 里不要做耗时的操作,现在也不需要担心这个问题,因为 QMUIThemeImage 内部增加了缓存。

新增功能

  1. UINavigationController (QMUI) 增加 qmui_isPushingqmui_isPoppingqmui_topViewController
  2. QMUICommonDefines.h 增加宏 QMUIStatusBarStyleDarkContent 用于 iOS 13 下不管当前是 Light/Dark Mode,都希望状态栏显示为黑色文字内容的场景,作为 -[UIViewController preferredStatusBarStyle] 的返回值使用。
  3. QMUIHelper 增加 deviceName 方法用于获取当前设备的产品名称,例如 iPhone 11 Pro Max,而屏幕尺寸判断的系列方法也对2019年9月发布的新设备进行了兼容。
  4. QMUINavigationControllerAppearanceDelegate 增加方法 navigationBarStyle 用于控制导航栏的 style。
  5. UIViewController (QMUI) 增加 qmui_animateAlongsideTransition:completion: 用于在转场过程中让一些操作跟随转场动画一起呈现出来。
  6. UISearchBar (QMUI) 增加 qmui_generateTextFieldBackgroundImageWithColor: 用于生成搜索框内的输入框背景图,增加 qmui_generateBackgroundImageWithColor:borderColor: 用于生成搜索框的背景图。
  7. 配置表增加 NavBarShadowImageColor 用于以颜色的方式设置导航栏分隔线。
  8. 配置表增加 TabBarItemImageColor 用于设置 UITabBarItem 未选中时的图片颜色。
  9. 配置表增加 TabBarItemImageColorSelected 用于设置 UITabBarItem 选中时的图片颜色。
  10. 配置表增加 SearchBarTextFieldBackgroundImage,废弃 SearchBarTextFieldBackground,以支持直接设置一个 UIImage 作为搜索框内的输入框背景,通过 iOS 13 的方式指定一个支持 Dark Mode 的 image asset,即可让搜索框里的输入框也支持 Dark Mode。
  11. 配置表增加 SearchBarBackgroundImage,废弃 SearchBarBottomBorderColorSearchBarBarTintColor ,以支持直接设置一个 UIImage 作为搜索框的背景图,通过 iOS 13 的方式指定一个支持 Dark Mode 的 image asset,即可让搜索框背景也支持 Dark Mode。

会带来 QMUI 新旧版本兼容问题的更新

  1. QMUINavigationControllerAppearanceDelegate 删除之前已被标记为废弃的方法 shouldSetStatusBarStyleLight
  2. QMUIHelper 删除之前已被标记为废弃的方法 renderStatusBarStyleDarkrenderStatusBarStyleLight
  3. QMUIConfiguration 删除 tabBarTintColor 属性,用新增的 tabBarItemImageColortabBarItemImageColorSelected 配合之前已有的 tabBarItemTitleColortabBarItemTitleColorSelected 来实现对 UITabBarItem 更精准的样式配置。
  4. QMUIConfiguration 删除 searchBarBottomBorderColorsearchBarBarTintColor 属性,改为用新增的 searchBarBackgroundImage 代替。
  5. UISearchBar (QMUI) 里,对于 iOS 11 及以后的系统,搜索框内的输入框背景图的高度从 28 改为 36,以保持与系统默认高度一致,请知悉。
  6. 相册选择控件里,对于“已隐藏”相簿,排序会强制放到相簿列表的最后面。

如何适配新版

  1. 全局搜索“[QMUIThemeManager sharedInstance]”,将其替换为“QMUIThemeManagerCenter.defaultThemeManager”。
  2. 全局搜索对 shouldSetStatusBarStyleLight 的使用并将其换成系统的 preferredStatusBarStyle 方法。
  3. 全局搜索 ”[QMUIHelper renderStatusBarStyleDark]“、”[QMUIHelper renderStatusBarStyleLight]“ 并将其删除,改为使用系统的 setNeedsStatusBarAppearanceUpdate

如果你有使用配置表

  1. 增加以下代码到配置表里:

    QMUICMI.navBarShadowImageColor = nil; // NavBarShadowImageColor : UINavigationBar.shadowImage 的颜色,如果为 nil,则显示系统默认 shadowImage,如果为全透明,则不显示 shadowImage,如果为除了 nil 和全透明外的其他颜色,则会将这个颜色叠加到 NavBarShadowImage 上显示出来,如果不存在 NavBarShadowImage,则使用一张 1px 高的图片作为默认图。
  2. 删除 TabBarTintColor,并增加以下代码:

    QMUICMI.tabBarItemImageColor = xxx; // TabBarItemImageColor : UITabBarItem 未选中时的图片颜色
    QMUICMI.tabBarItemImageColorSelected = xxx; // TabBarItemImageColorSelected : UITabBarItem 选中时的图片颜色
  3. 删除 SearchBarTextFieldBackground,改为用新的 SearchBarTextFieldBackgroundImage,如果需要以代码的方式生成输入框的背景图,可使用新增的 + [UISearchBar (QMUI) qmui_generateTextFieldBackgroundImageWithColor:]

    QMUICMI.searchBarTextFieldBackgroundImage = [UISearchBar qmui_generateTextFieldBackgroundImageWithColor:xxx]; // SearchBarTextFieldBackgroundImage : QMUISearchBar 里的文本框的背景图,图片高度会决定输入框的高度
  4. 删除 SearchBarBottomBorderColorSearchBarBarTintColor,并增加以下代码:

    QMUICMI.searchBarBackgroundImage = [UISearchBar qmui_generateBackgroundImageWithColor:xxx borderColor:xxx]; // SearchBarBackgroundImage : 搜索框的背景图,如果需要设置底部分隔线的颜色也请绘制到图片里

Bugfix

  1. #618 修复配置表的 TabBarShadowImage 在 iOS 13 下不生效的 bug,由于这里使用了 iOS 13 新增的 UITabBarAppearance 来设置,会导致以前那种设置样式的接口不生效或有问题,这是系统的限制,因此我们在 UITabBar (QMUI) 里对旧版本接口做了兼容,如果你在 iOS 13 下使用旧版本的接口,会帮你转换成新版本的接口来使用,请知悉。
  2. #629 修复某些特定情况下手势返回过程中,上一个界面的 navigationBar 被隐藏的 bug。
  3. #639 修复 QMUIModalPresentationViewController 以 showInView 的方式显示在 vc.view 上后,如果 push 界面再回来,vc 上的 modal 会消失的 bug。
  4. #649 修复显示带输入框的 QMUIAlertController 时会提示 becomeFirstResponder 错误的 bug。
  5. #654 修复 push/pop 时 UINavigationBar 返回按钮的文字颜色错误的 bug。
  6. #659 #701 修复 iOS 13 下 UIMenuControllerwindowLevel 变化引发的一系列菜单不可见的问题。
  7. #663 修复 QMUIMutipleDelegates 无法正确响应 conformsToProtocol: 的 bug。
  8. #679 修复 QMUIPopupContainerViewUIScrollView 里使用时的布局 bug。
  9. #680 修复 UIKit 在 UISearchController 显示搜索结果的时候进行 push/pop 操作后可能产生的界面异常的 bug。
  10. #692 修复 present 一个 QMUINavigationController 时,rootViewControllernavigationBarTintColor 无效的 bug。
  11. #693 修复 iOS 13.0 把 UIButton 作为 UITableViewCellaccessoryView 使用时会出现布局错误的 bug,iOS 13.1 不会。
  12. #698 修复 QMUICommonViewController 在调用 showEmptyView 之前访问不到 self.emptyView 的问题。
  13. #700 修复存在 present viewController 的情况下 QMUITheme 无法正确更新界面的 bug。
  14. #715 修复 4.0.0-beta 里对 viewController 横竖屏方向的控制有问题的 bug。
  15. 修复 DEVICE_WIDTHDEVICE_HEIGHT 在某些情况下计算不准确的 bug。
  16. 修复 QMUICollectionViewPagingLayoutcollectionView.bounces = NO 时会产生滚动异常的 bug。
  17. 修复 iOS 10、11 下使用 QMUIThemeColor 作为 UILabel.attributedText 的 foregroundColor,当主题发生变化时无法正确刷新文字颜色的 bug。
  18. 修复 iOS 11 及以下使用 QMUIThemeColor 作为 UITextView.typingAttributes 的 foregroundColor,当主题发生变化时无法正确刷新文字颜色的 bug。
  19. 修复使用 Xcode 11 编译到 iOS 9.0 上启动后会因为 Symbol not found: OBJC_CLASS$_PHLivePhotoRequestOptions 而 crash 的系统 bug。