【问题标题】:UIActivityIndicatorView dialog over viewUIActivityIndi​​catorView 对话框概览
【发布时间】:2016-06-13 07:24:33
【问题描述】:

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

结果是这样的:

我在某个地方看到了可以改用这样的东西:

我该怎么办?

提前致谢。

【问题讨论】:

  • 你是指昏暗的背景?
  • NVActivityIndicatorViewable 不适合你吗?
  • @SonLe 是的,我想这就是我要搜索的内容
  • 将此协议一致性添加到您的视图控制器中,您将获得可以使用的 startActivityAnimatingstopActivityAnimating 方法。
  • @Jigen 将空视图的颜色设置为黑色,并将其 alpha 设置为 0.5。

标签: ios swift uiview uiactivityindicatorview


【解决方案1】:

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

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()

【讨论】:

    【解决方案2】:

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

    //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()
    

    【讨论】:

      猜你喜欢
      • 2012-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多