UIActivityIndi​​catorView 对话框概览

UIActivityIndicatorView dialog over view

在我的应用程序中,我使用了自定义 UIActivityIndi​​cator 视图 (this),它运行良好。 我有一个 UITableView,我希望在加载数据时在 tableview 上显示指示器。为了解决这个问题,我创建了一个带有背景的空视图,当我需要启动指示器的动画时,我只需隐藏 tableview 并显示空视图 + 指示器。

结果是这样的:

我在某处看到可以使用类似这样的东西:

我该怎么办?

提前致谢。

您可以尝试在 Table 视图上添加一个半透明的黑色视图,并将自定义 activity 指示器代码作为子视图放在黑色视图中。

let aBlackView = UIView(frame: CGRectMake(0, 0, self.view.bounds.width, self.view.bounds.height))
aBlackView.backgroundColor = UIColor.blackColor()
aBlackView.alpha = 0.75 // Change the alpha depending on how much transparency you require

let aMainWindow = UIApplication.sharedApplication().delegate!.window
aMainWindow!!.addSubview(aBlackView)

/* Enter you code for NVActivityIndicatorViewable here */

aBlackView.addSubview(/* NVActivityIndicatorViewable */)

完成您的请求后,您可以通过调用以下代码删除黑色视图:

aBlackView.removeFromSuperview()

我创建了一个 activity 显示屏幕。我在项目的每个地方都使用了。

//ProgressBarNotification.swift

 import Foundation
 import UIKit

class ProgressBarNotification {

internal static var strLabel = UILabel()
internal static var messageFrame = UIView()
internal static var activityIndicator = UIActivityIndicatorView()    

internal static func progressBarDisplayer(msg:String,indicator:Bool ){


    let view1 = UIApplication.sharedApplication().delegate?.window!!.rootViewController?.view

    view1?.userInteractionEnabled = false

    strLabel = UILabel(frame: CGRect(x: 50, y: 0, width: 200, height: 50))
    strLabel.text = msg
    strLabel.textColor = UIColor.whiteColor()
    messageFrame = UIView(frame: CGRect(x: view1!.frame.midX - 90, y: view1!.frame.midY - 25 , width: 180, height: 50))
    messageFrame.layer.cornerRadius = 15
    messageFrame.backgroundColor = UIColor(white: 0, alpha: 0.7)
    if indicator {
        activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.White)
        activityIndicator.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
        activityIndicator.startAnimating()
        messageFrame.addSubview(activityIndicator)
    }
    messageFrame.addSubview(strLabel)
    view1!.addSubview(messageFrame)


}

internal static func removeProgressBar() {

    let view1 = UIApplication.sharedApplication().delegate?.window!!.rootViewController?.view

    _ = view1?.subviews.filter({ (view) -> Bool in
        if view == ProgressBarNotification.messageFrame {
            view.removeFromSuperview()
        }
        return false
    })

    ProgressBarNotification.messageFrame.removeFromSuperview()

    view1?.userInteractionEnabled = true

}

  deinit{

  }
}

用法

    //To start Loader

    ProgressBarNotification.progressBarDisplayer("Loading", indicator: true)

   //Stop 

    ProgressBarNotification.removeProgressBar()