Swift 3 - 缩放RoundView

时间:2017-08-07 21:30:54

标签: ios swift uiimageview uicollectionview

我的ReusableCollectionView中有一个圆形的Imageview。 当我向下滚动我的collectionView时,我会缩放我的Imageview,一旦它滚动回到位置,我就将它缩放到原始大小。

 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)
}

在执行此操作时,imageview不再是圆形。

这是一个可视化问题的图像:

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

这就是我解决问题的方法:

imageView.autoresizesSubviews = false