Kalaivanan Sm
Kalaivanan Sm

Reputation: 1

How do i animate scrollview?

How can I create such animations or custom transitions in scroll view. You can see the expected animation in the GIF : https://gfycat.com/EveryBackLhasaapso

Expecting:

On longpress over the scrollview, it needs to get expand like the gif animation and the icon also need to get zoomin.

I have tried to attain this using a scrollview, but the animation doesn't matches as expected.

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}

Upvotes: 0

Views: 37

Answers (1)

MRizwan33
MRizwan33

Reputation: 2741

Now run your application.

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}

Upvotes: 1

Related Questions