我正在使用快速的ActivityIndicator: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上启动NVAcitivityIndicatorPresenter的重要性。
是否要在触发MLRequest之前显示此损坏指示?
答案 0 :(得分:0)
将rumMlmodel设置为延迟功能,不要在异步任务中添加活动代码。之后,它将显示您的活动。延迟应该在0.4-0.6
左右