gpt4 book ai didi

ios - 在 CoreML VNCoreMLRequest 之前触发时 ActivityIndi​​cator 不显示

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

我正在使用 swift ActivityIndi​​cator : https://github.com/ninjaprox/NVActivityIndicatorView

func runMLModel(image: CIImage, completion: @escaping ([MLMultiArray]) -> Void){
let request = VNCoreMLRequest(model: myModel) { (request, error) in
guard let results = request.results as? [VNCoreMLFeatureValueObservation] else {
fatalError("Model failed to process image")
}
//Do work here get mlData var
completion(mlData)
}

let handler = VNImageRequestHandler(ciImage: image)

do {
try handler.perform([request])
}catch {
print(error)
}
}

func buttonPressedToDoMLWork(){

self.startAnimating(CGSize(width: 200, height: 200), message: "loading", type: NVActivityIndicatorType.audioEqualizer)
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()) {
NVActivityIndicatorPresenter.sharedInstance.setMessage("Authenticating...")

}
// Activity Indicator should be showing up here
// but nothing is displayed
runMLModel(image: myImage, completion: { (mlData : [MLMultiArray]) in

print("got data")

//indicator only shows up NOW.. after printing
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1) {
self.stopAnimating(nil)

}
})
}
}

CoreML 模块内的代码似乎覆盖了在主 DispatchQueue 上启动 NVAcitivityIndi​​catorPresenter 的重要性。

有办法让这个该死的指示器在 MLRequest 被触发之前显示出来吗?

最佳答案

将您的 rumMlmodel 放入延迟函数中,不要在异步任务中添加事件代码。之后它将显示您的事件。延迟应该在 0.4 - 0.6 左右

关于ios - 在 CoreML VNCoreMLRequest 之前触发时 ActivityIndi​​cator 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51566527/

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