Search code examples
iosswiftuiimageviewuiimagetvos

tvOS: UIImageView with rounded corners without losing the focus animation


I am displaying a collection view with an UIImageView for each cell. My images are being animated on cell focus (the standard animation where the image pops out).

However, I also need to round the corners of the image by setting the imageView.layer.cornerRadius. The problem is that once I set maskToBounds = true my imageView stops popping out on focus and without that I cannot achieve the rounded corners.

I’ve checked in other SO questions and some people suggested post-process the image in runtime using Core Graphics but this is too much processing for my collectionView.

Is there any alternative to achieve this? (The iTunes movie app does it, so I suppose there must be)


Solution

  • Setting maskToBounds crops the image when focused because the cell extends out of its bounds to get the parallax animation.

    The issue is that to generate rounded corners with that method you need to set maskToBounds to true.

    So... your final goal could be achieved using a different method to generate rounded corners, via CoreGraphics for example, that does not require setting maskToBounds.

    Or, what I am personally doing, to use this open source library, which allows adding parallax effect to any UIView https://github.com/PGSSoft/ParallaxView