Ich möchte geänderte UIView als UIImage speichern. Es wird jedoch immer als erste (Standard) Ansicht gespeichert.Wie konvertiert (bearbeitet) UIView in UIImage?
Dies ist die erste (Standard) UIView.
Die App nutzt Gradient Animation, die Farbe zu ändern. Die veränderte UIView ist das gleiche wie das folgende Bild:
Ich schrieb den Code wie folgt:
extension UIImage {
convenience init(layer: CALayer, view: UIView) {
UIGraphicsBeginImageContext(view.frame.size)
layer.render(in: UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
self.init(cgImage: (image?.cgImage)!)
}
}
By the way, das Bild wurde mit dem Standard-UIView gespeichert.
Wie kann ich das Bild mit der geänderten UIView speichern?
[EDIT] Animation hinzufügen-Code
func animateLayer(){
if index == 11 {
addEmitter(a: index, b: 0)
fromColors = [Colors.fromColorList[index], Colors.fromColorList[0]]
toColors = [Colors.toColorList[index], Colors.toColorList[0]]
index = 0
} else {
addEmitter(a: index, b: index + 1)
fromColors = [Colors.fromColorList[index], Colors.fromColorList[index+1]]
toColors = [Colors.toColorList[index], Colors.toColorList[index+1]]
index += 1
}
animation.fromValue = fromColors
animation.toValue = toColors
animation.duration = 1.00
mind.mindAnimation(animation: animation)
}
[EDIT 2] Fügen Sie die ViewDidAppear
override func viewDidAppear(_ animated: Bool) {
animation.isRemovedOnCompletion = false
animation.fillMode = kCAFillModeForwards
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.delegate = self
}
Code für Animation auch in Frage. Du musst dich dort ändern. – adev
@adev Code für Animation hinzufügen. Vielen Dank. –
Versuchen Sie dies, 'animation.removedOnCompletion = false ', bevor Sie Animationen hinzufügen. – adev