我有tabbarcontroller,其中有5个标签我想在按下标签栏并且用户正在等待视图加载时显示包含活动指示符的叠加层。视图控制器包含从服务器获取数据的功能,因此我需要显示加载活动指示器。但是,当我把它放在viewWillDisappear
或viewWillAppear
时,它就不会来。因此,当我选择一个项目时,我正试图在tabbarcontroller中进行此操作。但它没有发生。在视图转换到新视图后加载activityindicator。加载覆盖应该是立即的。
override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem){
dispatch_async(dispatch_get_global_queue((QOS_CLASS_UTILITY), 0)) {
dispatch_async(dispatch_get_main_queue()) {
LoadingOverlay.shared.showOverlay(self.view)
}
}}
public class LoadingOverlay{
var overlayView = UIView()
var activityIndicator = UIActivityIndicatorView()
class var shared: LoadingOverlay {
struct Static {
static let instance: LoadingOverlay = LoadingOverlay()
}
return Static.instance
}
public func showOverlay(view: UIView) {
overlayView.frame = CGRectMake(0, 0, 80, 80)
overlayView.center = view.center
overlayView.backgroundColor = UIColor(white: 0.5, alpha: 0.7)
overlayView.clipsToBounds = true
overlayView.layer.cornerRadius = 10
activityIndicator.frame = CGRectMake(0, 0, 40, 40)
activityIndicator.activityIndicatorViewStyle = .WhiteLarge
activityIndicator.center = CGPointMake(overlayView.bounds.width / 2, overlayView.bounds.height / 2)
overlayView.addSubview(activityIndicator)
view.addSubview(overlayView)
activityIndicator.startAnimating()
}
public func hideOverlayView() {
activityIndicator.stopAnimating()
overlayView.removeFromSuperview()
} } `
答案 0 :(得分:0)
请使用IJProgressView库显示HUD
使用方法: 要显示进度视图,
IJProgressView.shared.showProgressView(view)
要隐藏进度视图,
IJProgressView.shared.hideProgressView()