我在鍵盤輸入視圖中有一個按鈕和一個集合視圖(水平)。自動佈局被使用。 Leading Constraint設置爲-50,該按鈕默認隱藏。當用戶開始使用集合視圖並且contentOffset.x的集合視圖大於80時,該按鈕將顯示。代碼工作正常,但動畫不起作用。動畫不能在swift中工作
extension ViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if self.collectionView.contentOffset.x > 80 {
UIView.animate(withDuration: 1, delay: 0, options: .curveEaseIn, animations: {
self.sideButtonLeadingConstraint.constant = 0
self.view.layoutIfNeeded()
}, completion: nil)
} else {
UIView.animate(withDuration: 1, delay: 0, options: .curveEaseIn, animations: {
self.sideButtonLeadingConstraint.constant = -50
self.view.layoutIfNeeded()
}, completion: nil)
}
}
}
項目鏈接https://drive.google.com/file/d/0B5UHWsK1E6dSTFh4ZDJxMmxpYUE/view?usp=sharing –