<分区>
我有一个事件指示器,它在长时间运行的进程之前显示。 在此过程之后,我只是尝试再次删除该指示器。
我做不到。指示器出现但随后永远停留在我的屏幕上,即使我在主线程中将其删除也是如此。
有人可以帮助我吗?
代码:
// Activity Indicator Variables
var messageFrame = UIView()
var activityIndicator = UIActivityIndicatorView()
var strLabel = UILabel()
// in viewdidappear
showprogressIndicator("Please Wait", true)
dispatch_async(dispatch_get_main_queue()) {
sleep(2); // LONG RUNNING TASK
dispatch_async(dispatch_get_main_queue()) {
for subview in self.messageFrame.subviews {
subview.removeFromSuperview();
}
self.messageFrame.removeFromSuperview()
//self.saveButton.enabled = true
}
}
func showprogressIndicator(msg:String, _ indicator:Bool ) {
var strLabel = UILabel(frame: CGRect(x: 50, y: 0, width: 200, height: 50))
strLabel.text = msg
strLabel.textColor = UIColor.whiteColor()
var messageFrame = UIView(frame: CGRect(x: view.frame.midX - 90, y: view.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)
view.addSubview(messageFrame)
//self.messageFrame.removeFromSuperview()
}