gpt4 book ai didi

swift - 在调用方法之前添加 subview

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

我遇到了一个非常奇怪的问题。首先是我的代码:

func viewDuringLoading(){
var tabBarSize = self.tabBarController?.view.bounds.size

hider = UIView(frame: CGRectMake(0, 0, tabBarSize!.width, tabBarSize!.height))
hider.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.5)


indicator = UIActivityIndicatorView(frame: CGRectMake(hider.bounds.width/2 - 25, hider.bounds.height/2 - 25, 50, 50))

indicator.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.6)

hider.addSubview(indicator)
indicator.startAnimating()

self.tabBarController?.view.addSubview(hider)

checkProducts()

}

如您所见,我向 View 添加了一个 subview ,然后调用我的非异步方法 checkProducts。我现在的问题是,在我的 checkProducts 完成工作后, subview 被添加到我的 View 中。

我该如何解决这个问题?我考虑过使用异步线程。但似乎不起作用。

最佳答案

取决于您在 checkProgress 中执行的操作。根据您的说法,听起来 checkProgress 是一种同步方法,它会阻塞主线程,从而阻止您的 View 添加为 subview 。

checkProgress 方法有什么作用?当你异步运行它时发生了什么?如果它完全阻塞主线程,那么无论它是否阻塞主线程,它可能都应该是异步的。

关于swift - 在调用方法之前添加 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28268446/

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