如何在 ScrollView 中创建此类动画或自定义过渡。您可以在 GIF 中看到预期的动画:https://gfycat.com/EveryBackLhasaapso
期待:
在 ScrollView 上长按,它需要像gif动画一样展开,图标也需要放大。
我尝试使用 ScrollView 实现此目的,但动画与预期不匹配。
UIView.animate(withDuration: 0.2, delay: 0.2, usingSpringWithDamping: 0.5, initialSpringVelocity: 1, options: .curveEaseInOut, animations: {
self.scrollViewHeight.constant = isExpanded == true ? ViewConstants.collectionViewHeightWithExpand : ViewConstants.collectionViewHeightWithcollapse
self.scrollContentViewHeight.constant = isExpanded == true ? ViewConstants.collectionViewHeightWithExpand : ViewConstants.collectionViewHeightWithcollapse
self.scrollContentView.transform = isExpanded == true ? CGAffineTransform(scaleX: 1.20, y: 1.20) : CGAffineTransform.identity
self.view.layoutIfNeeded()
}) { _ in}
最佳答案
现在运行您的应用程序。
self.scrollViewHeight.constant = isExpanded == true ? ViewConstants.collectionViewHeightWithExpand : ViewConstants.collectionViewHeightWithcollapse
self.scrollContentViewHeight.constant = isExpanded == true ? ViewConstants.collectionViewHeightWithExpand : ViewConstants.collectionViewHeightWithcollapse
UIView.animate(withDuration: 0.2, delay: 0.2, usingSpringWithDamping: 0.5, initialSpringVelocity: 1, options: .curveEaseInOut, animations: {
self.scrollContentView.transform = isExpanded == true ? CGAffineTransform(scaleX: 1.20, y: 1.20) : CGAffineTransform.identity
self.view.layoutIfNeeded()
}) { _ in}
关于ios - 如何为 ScrollView 设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55356040/