我创建了UIView
的扩展程序并创建了ActivityIndicatorView
,并将其作为子视图添加到UIApplication
Window
。现在,当设备旋转时,UIViewController
也会旋转而不是ActivityIndicatorView
。
internal extension UIView{
func showActivityViewWithText(text: String?) -> UIView{
let window = UIApplication.sharedApplication().delegate?.window!!
let baseLineView = window!.viewForBaselineLayout()
let locView = UIView(frame:window!.frame)
locView.backgroundColor = UIColor.clearColor()
locView.center = window!.center
baseLineView.addSubview(locView)
baseLineView.bringSubviewToFront(locView)
let overlay = UIView(frame: locView.frame)
overlay.backgroundColor = UIColor.blackColor()
overlay.alpha = 0.35
locView.addSubview(overlay)
locView.bringSubviewToFront(overlay)
let hud = UIActivityIndicatorView(activityIndicatorStyle: .WhiteLarge)
hud.hidesWhenStopped = true
hud.center = CGPoint(x: locView.frame.size.width/2,
y: locView.frame.size.height/2)
hud.transform = CGAffineTransformMakeScale(1, 1)
hud.color = UIColor.redColor()
hud.startAnimating()
locView.addSubview(hud)
locView.bringSubviewToFront(hud)
}
答案 0 :(得分:2)
可能是问题是错过自动修复面膜?尝试添加:
hud.autoresizingMask = [ .flexibleTopMargin, .flexibleBottomMargin, .flexibleLeftMargin, .flexibleRightMargin ]
我想hud
locView
autoresizingMask
是locView
的子视图的原因我认为是...
TimeSpan total = new TimeSpan(0);
total.Add(timeTaken1);
total.Add(timeTaken2);
total.Add(timeTaken3);
...
。