gpt4 book ai didi

iOS Swift 动画有时不起作用

转载 作者:行者123 更新时间:2023-11-29 05:18:49 26 4
gpt4 key购买 nike

无法解决自定义弹出窗口中显示动画的问题。在我的应用程序中,我使用 SwiftEntryKit 通过自定义 View 显示顶部警报。此自定义 View 包含动画

        UIView.animate(
withDuration: 0.8,
delay: 0.0,
options: [.autoreverse, .repeat],
animations:
{
let scale = CGAffineTransform(scaleX: 1.3, y: 1.3)
self.img.transform = scale
}, completion: nil)

一切都按预期进行,我可以显示带有缩放动画的弹出窗口。

但是当我在使用 RxSwift 进行网络调用后调用完全相同的弹出窗口时,动画不起作用。没有错误没有信息, View 只是放大了 1.3 尺寸并且不显示动画。这是我的网络代码的一部分

        HelperAuth.makeRegister(name: name!, email: email!, password: password!)
.observeOn(MainScheduler.instance)
.subscribe(onNext:
{ reponse in

print(reponse)
}, onError:
{ error in
MessagesManager.showRedAlerter(text: "ERRRRAR")//here is my method to show popup with animation
}).disposed(by: coordinatorAuth.disposeBag)

找不到这种奇怪行为的任何原因。

最佳答案

正如 Dhaval Raval 在评论中提到的,在完成其他动画 block 时包装动画可以解决动画问题。

我将动画代码更改为

        UIView.animate(
withDuration: 0.0,
animations: {
}, completion:
{ _ in
UIView.animate(
withDuration: 0.8,
delay: 0.0,
options: [.autoreverse, .repeat],
animations:
{
let scale = CGAffineTransform(scaleX: 1.3, y: 1.3)
self.img.transform = scale
}, completion: nil)
})

现在它可以正常工作,从正常的方法调用到 RxSwift Networking 调用之后

关于iOS Swift 动画有时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58890459/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com