這裏是我的代碼,鍵盤出現時將一個視圖切換了(注意,這個觀點有一個CollectionView
):斯威夫特的iOS 9鍵盤出現不移位觀看,但工作在iOS的10
if isKeyboardShowing {
UIView.animate(withDuration: animationDuration, animations: {
if self.isCollectionViewBlockingInput() {
self.view.frame.origin.y = -distanceShifted
// Keyboard is shifted less because view already shifts by distance
self.bottomConstraintForInput.constant = -keyboardViewEndFrame.height + distanceShifted
} else {
self.bottomConstraintForInput.constant = -keyboardViewEndFrame.height
}
})
}
本質視圖的原點y向上移動一定距離。這適用於iOS 10,但在iOS 9 **中,當視圖第一次加載並且我第一次打開鍵盤時,視圖會嘗試向上移動但失敗。相反,一個黑色的背景似乎暫時下移,然後消失:
這只是發生在滾動集合視圖之前打開鍵盤。一旦我開始滾動收藏視圖,錯誤消失,鍵盤再次正確移動。
此外,此錯誤並未在iOS 10中顯示。
你爲什麼不叫UIView'的'了'layoutIfNeeded'方法,並使用完畢塊動畫和編寫裏面。 –