Translate the following objc code to swift:…
- User
Translate the following objc code to swift: -(void)startAnimatingWithCGImages:(NSArray*)cgImages CompletionBlock:(Block)block delay:(NSTimeInterval)delay keepLastFrame:(BOOL)keepLastFrame { [self setblock:block]; CAKeyframeAnimation *anim = [CAKeyframeAnimation animation]; [anim setKeyPath:CONTENTS]; [anim setValues:cgImages]; [anim setRepeatCount:self.animationRepeatCount]; [anim setDuration:self.animationDuration]; anim.delegate = self;
if (delay > 0) { anim.beginTime = CACurrentMediaTime() + delay; } if (keepLastFrame) { [anim setRemovedOnCompletion:NO]; [anim setFillMode:kCAFillModeBoth]; } CALayer *ImageLayer = self.layer; [ImageLayer addAnimation:anim forKey:nil];}
- Assistant
func startAnimatingWithCGImages(cgImages: [Any]?, completionBlock block: @escaping () -> Void, delay: TimeInterval, keepLastFrame: Bool) { setBlock(block) let anim = CAKeyframeAnimation() anim.keyPath = .contents anim.values = cgImages anim.repeatCount = animationRepeatCount anim.duration = animationDuration anim.delegate = self
if delay > 0 { anim.beginTime = CACurrentMediaTime() + delay } if keepLastFrame { anim.isRemovedOnCompletion = false anim.fillMode = .both } let imageLayer = layer imageLayer.add(anim, forKey: nil)}
- User
How can i end the thread once the lottie animation is finished? code: @objc public func refreshCustomAnimationActionAlert(nameImage: String, sequenceinit: Int, sequenceEnd: Int, duration: Double, changeTitle: String?, endAnimation: @escaping Block) { guard isWindoLoaded else { print("Invoke showCustomAnimationActionAlert after ViewDidLoad"); return }
mainThreadAsyncBlock { if let title = changeTitle { self.lblTitle.text = title } self.lottieUpload.removeLottieAnimation() self.lottieUpload.addLottieRangeOnView(self.imgViewAnimation, "loader-check", 1, .scaleAspectFit, 91, 134) } } - Assistant
To end the thread once the Lottie animation is finished, you can update the
refreshCustomAnimationActionAlertmethod as follows:@objc public func refreshCustomAnimationActionAlert(nameImage: String, sequenceinit: Int, sequenceEnd: Int, duration: Double, changeTitle: String?, endAnimation: @escaping () -> Void) { guard isWindowLoaded else { print("Invoke showCustomAnimationActionAlert after ViewDidLoad"); return } mainThreadAsyncBlock { if let title = changeTitle { self.lblTitle.text = title } self.lottieUpload.removeLottieAnimation() self.lottieUpload.addLottieRangeOnView(self.imgViewAnimation, "loader-check", 1, .scaleAspectFit, 91, 134) self.lottieUpload.animationView?.loopMode = .playOnce self.lottieUpload.animationView?.play { _ in endAnimation() } } }In this updated code:
- The
endAnimationcompletion block is changed to .
- The