Mike Mike -3 years ago 291
Swift Question

Swift 3 - Scale round ImageView

I have a round Imageview in my ReusableCollectionView.
When I scroll down my collectionView I scale my Imageview and as soon as it scrolls back to place I scale it to its original size.

func scrollViewDidScroll(_ scrollView: UIScrollView) {
// Exit early if swiping up (scrolling down)
if scrollView.contentOffset.y > 0 { return }

// this is just a demo method on how to compute the scale factor based on the current contentOffset

var scale = 1.0 + fabs(scrollView.contentOffset.y) / scrollView.frame.size.height

//Cap the scaling between zero and 1
scale = max(0.0, scale)

// Set the scale to the imageView
headerView.imageview.transform = CGAffineTransform(scaleX: scale, y: scale)

headerView.categoryButton.transform = CGAffineTransform(scaleX: scale, y: scale)

The imageview is not round anymore while doing so.

Here is an image visualising the problem:

enter image description here

enter image description here

Answer Source

This is how I solved the problem:

imageView.autoresizesSubviews = false
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download