如何在滚动视图中创建此类动画或自定义转场。您可以在GIF中看到预期的动画:https://gfycat.com/EveryBackLhasaapso
长按滚动视图时,它需要像gif动画一样展开,并且图标也需要放大。
我试图使用滚动视图来实现这一点,但是动画与预期的不匹配。
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}
答案 0 :(得分:1)
现在运行您的应用程序。
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}