【发布时间】:2017-09-27 03:24:35
【问题描述】:
我有这个方法
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView is GLIndexedCollectionView { return }
if scrollView.contentOffset.y >= 120 && self.navBarHidden == true {
self.navBarHidden = false
self.setNeedsStatusBarAppearanceUpdate()
self.topTvConstraint.constant = 44.0
self.view.layoutIfNeeded()
self.navigationBarConstraint.constant = 65
UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseOut, animations: {
self.view.layoutIfNeeded()
}, completion: nil)
var scrollBounds = self.tv.bounds
scrollBounds.origin = CGPoint(x: 0, y: 185)
self.tv.bounds = scrollBounds
}
}
想法是动画一个顶部栏并改变状态栏颜色,所以我使用 setNeedsStatusBarAppearanceUpdate 来
override var preferredStatusBarStyle: UIStatusBarStyle {
if navBarHidden {
return .lightContent
}
return .default
}
但是....如果我在 Xcode 9 中编译并在带有 iOS 11 的真实设备或模拟器中运行它,它会在这一行崩溃
self.setNeedsStatusBarAppearanceUpdate()
如果我尝试 iOS 10.3 按预期运行,为什么?请帮忙!
【问题讨论】:
-
你必须检查设备版本才能调用这个方法
-
但该方法在 iOS11 中并没有被弃用,不是吗?
-
检查我的答案,这在项目中对我有用,所以我与你分享