// ScrollView Delegate 中
// MARK: - 发送按钮滑动动画
/// 滑动时隐藏按钮,需判断滑动范围,和是否拖动。否则下拉刷新、push进其他页后再回到本页会导致按钮隐藏,而停止方法未调用,按钮隐藏后没有自动出现的bug。
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView.contentOffset.y > 0 {
if scrollView.isDragging {
UIView.animate(withDuration: 0.5) {
self.postButton.transform = CGAffineTransform(translationX: 127, y: 0)
}
}
}
}
/// 停止拖动,显示按钮
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if decelerate == false {
UIView.animate(withDuration: 0.5) {
self.postButton.transform = .identity
}
}
}
/// 滚动停止,显示按钮
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
UIView.animate(withDuration: 0.5) {
self.postButton.transform = .identity
}
}