2021年3月20日星期六

Invert simple UIView mask (cut hole instead of clip to circle) [duplicate]

I'm trying to avoid CAShapeLayer because I would need to mess with CABasicAnimation, not UIView.animate. So instead, I'm just using UIView's mask property to mask views. Here's my code currently:

class ViewController: UIViewController {      override func viewDidLoad() {          super.viewDidLoad()                    let imageView = UIImageView(frame: CGRect(x: 50, y: 50, width: 200, height: 300))          imageView.image = UIImage(named: "TestImage")          imageView.contentMode = .scaleAspectFill          imageView.clipsToBounds = true          view.addSubview(imageView)                    let maskView = UIView(frame: CGRect(x: 100, y: 100, width: 80, height: 80))          maskView.backgroundColor = UIColor.blue /// ensure opaque          maskView.layer.cornerRadius = 10                    imageView.mask = maskView /// set the mask      }  }  
Without imageView.mask = maskView With imageView.mask = maskView

It makes a portion of the image view visible. However, this is what I want:

Instead of making part of the image view visible, how can I cut a hole in it?

https://stackoverflow.com/questions/66725422/invert-simple-uiview-mask-cut-hole-instead-of-clip-to-circle March 21, 2021 at 03:06AM

没有评论:

发表评论