我在键盘输入视图中有一个按钮和一个集合视图(水平)。自动布局被使用。 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 –