我有這樣的方法scrollViewDidScroll崩潰的iOS調用self.setNeedsStatusBarAppearanceUpdate()當11
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中不被棄用,是不是? – goseta
檢查我的答案,這在我的項目中工作,所以我與你分享 –