gpt4 book ai didi

iOS:事件指示器停止后如何执行一段代码?

转载 作者:行者123 更新时间:2023-11-29 10:38:37 28 4
gpt4 key购买 nike

我需要一种方法来执行与下面类似的功能,但不是等待 3 秒,而是等待事件指示器被隐藏 [UIApplication sharedApplication].networkActivityIndi​​catorVisible = NO;。任何提示或建议表示赞赏。

double delayInSeconds = 3.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// lines of code
});

最佳答案

你如何使用Key-Value Observing :

声明上下文

static int NetworkActivityContext;

添加您的观察员

[[UIApplication sharedApplication] addObserver:self forKeyPath:@"networkActivityIndicatorVisible" options:NSKeyValueObservingOptionNew context:&NetworkActivityContext];

实现 KVO 回调

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (context == &NetworkActivityContext) {
BOOL isNetworkActivityVisible = [UIApplication sharedApplication].networkActivityIndicatorVisible;
if(!isNetworkActivityVisible){
//Do whatever work you need to do now that it's hidden
}
}
}

关于iOS:事件指示器停止后如何执行一段代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25692114/

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