在iOS 12和Xcode 10.3上,大标题滚动没有问题,但是使用相同的代码Xcode 11和iOS 13,我遇到了以下GIF所示的问题:
在iOS 12上,我的导航栏具有所需的行为,即:
有人遇到同样的问题吗?对于其余的部分,我当然会使用prefersLargeTitles = true
,并且我确定对于这2种不同的行为,我使用的代码是相同的。感谢您的帮助
答案 0 :(得分:2)
经过一些调查,我找到了解决方案,因此,我分享了我的发现,因为我认为这可以帮助某些人。
解决方案是,从iOS 13开始,我们必须使用UINavigationBarAppearance
。创建该对象后,可以将其分配给一些新属性,即:
standardAppearance
compactAppearance
scrollEdgeAppearance
(尤其可能是我的错误的原因)我将其示例作为扩展发布:
extension UINavigationBar {
func setupLarge() {
// ... Set up here your tintColor, isTranslucent and other properties if you need
if #available(iOS 11.0, *) {
prefersLargeTitles = true
//largeTitleTextAttributes = ...Set your attributes
}
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = barTintColor
appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
standardAppearance = appearance
compactAppearance = appearance
scrollEdgeAppearance = appearance
}
}
}