首页 > 解决方案 > 快速将蒙版转换为另一个带有动画的蒙版

问题描述

我想在动画中更改蒙版

但它就像换成另一个没有动画 屏幕记录的面具

我希望它看起来像这样

func creatMask(_ index: Int) -> CALayer {
    let layer = CALayer()
    let image = [#imageLiteral(resourceName: "bubble_1.png"),#imageLiteral(resourceName: "bubble_2.png"),#imageLiteral(resourceName: "bubble_3.png"),#imageLiteral(resourceName: "bubble_4.png"),#imageLiteral(resourceName: "bubble_5.png")]
    layer.contents = image[index].cgImage
    layer.contentsScale = image[index].scale
    layer.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
    return layer
}

@objc func transform() {
    UIView.animate(withDuration: 1) {
        self.redView.layer.mask = self.creatMask(1)
    }
}

}

标签: swiftuiviewanimation

解决方案


推荐阅读