【发布时间】:2015-08-11 09:22:01
【问题描述】:
我创建了一个需要 3 个输入的活动窗口函数,
- msg:String - 应该在活动窗口中显示的消息
- indicator:Bool - 是否应该显示活动窗口
- view:UIView - 应该从调用它的视图控制器获取帧大小等的 uiview
一切正常,除了需要删除子视图的部分。如果在主视图控制器上运行相同的功能。它工作正常。就在我将它移到 NSObject 时,它没有。请帮忙
class UIDesignFunction: NSObject {
func progressBarDisplayer(msg:String, indicator:Bool, view:UIView) {
var activityIndicator = UIActivityIndicatorView()
var strLabel = UILabel()
var msgFrame = UIView()
if indicator{
//println(msg)
strLabel = UILabel(frame: CGRect(x: 50, y: 0, width: 200, height: 50))
strLabel.text = msg
strLabel.textColor = UIColor.whiteColor()
msgFrame = UIView(frame: CGRect(x: view.frame.midX - 90, y: view.frame.midY - 25 , width: 180, height: 50))
msgFrame.layer.cornerRadius = 15
msgFrame.backgroundColor = UIColor(white: 0, alpha: 0.7)
activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.White)
activityIndicator.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
activityIndicator.startAnimating()
msgFrame.addSubview(activityIndicator)
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
msgFrame.addSubview(strLabel)
view.addSubview(msgFrame)
}else{
UIApplication.sharedApplication().endIgnoringInteractionEvents()
msgFrame.removeFromSuperview()
}
}
【问题讨论】:
-
mgFrame 一直显示并且不关闭
-
willRemoveSubview 不起作用 :( 你如何使用 removeFromSuperviewWithoutNeedingDisplay
-
@MugunthanBalakrishnan 我是否理解正确,您使用
indicator = true调用该函数一次以显示活动指示器,然后再次使用indicator = false以删除活动指示器? -
@hennes 是的,没错 :)