在我的应用程序中,我使用了一个自定义的UIActivityIndicator视图(this),它效果很好。 我有一个UITableView,我希望通过tableview上的指标加载数据。为了解决这个问题,我创建了一个带有背景的空视图,当我需要启动指标的动画时,我只需隐藏tableview并显示空视图+指标。UIActivityIndicatorView查看对话框
结果是这样的:
我看到的地方,我可以使用,而不是像这样:
我该怎么办?
在此先感谢。
在我的应用程序中,我使用了一个自定义的UIActivityIndicator视图(this),它效果很好。 我有一个UITableView,我希望通过tableview上的指标加载数据。为了解决这个问题,我创建了一个带有背景的空视图,当我需要启动指标的动画时,我只需隐藏tableview并显示空视图+指标。UIActivityIndicatorView查看对话框
结果是这样的:
我看到的地方,我可以使用,而不是像这样:
我该怎么办?
在此先感谢。
您可以尝试在表视图上添加半透明的黑色视图,并将自定义活动指示器代码作为子视图放置在黑色视图中。
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()
我创建显示屏幕的活动。我用在我的项目的每一个地方。
//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()
你的意思是昏暗的背景是什么? –
'NVActivityIndicatorViewable'不适合你吗? – srvv
@SonLe是的我认为这是我在寻找 – Jigen