Я добавил маску к моему представлению и теперь пытаюсь анимировать ее. Я попытался адаптировать решение из https://stackoverflow.com/a/36461202/642502, но оно не анимируется для мне. Я попытался поменять местами, где добавляется анимация, и удалить setDisabledActions, но продолжаю получать те же результаты.
extension UIView {
public func mask(with rect: CGRect?, inverse: Bool = false, animated: Bool = true, duration: TimeInterval = 1.0) {
guard let rect = rect else {
self.layer.mask = nil
return
}
let path = UIBezierPath(rect: rect)
let maskLayer = CAShapeLayer()
if inverse {
path.append(UIBezierPath(rect: self.bounds))
maskLayer.fillRule = .evenOdd
}
if animated {
let animation = CABasicAnimation(keyPath: "path")
animation.fromValue = maskLayer.path
animation.toValue = path.cgPath
animation.duration = duration
animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
animation.isRemovedOnCompletion = false
maskLayer.add(animation, forKey: "selectAnimation")
CATransaction.begin()
CATransaction.setDisableActions(true)
maskLayer.path = path.cgPath
self.layer.mask = maskLayer
CATransaction.commit()
} else {
maskLayer.path = path.cgPath
self.layer.mask = maskLayer
}
}
}