user4034967
user4034967

Reputation:

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

Upvotes: 2

Views: 222

Answers (1)

user4034967
user4034967

Reputation:

This is how I solved the problem:

imageView.autoresizesSubviews = false

Upvotes: 1

Related Questions