为了将这个Objective C的例子转换成Swift:How to flash screen programmatically?,我编写了以下代码:
但是我不确定应该在哪里添加
func blinkScreen(){
var wnd = UIApplication.sharedApplication().keyWindow;
var v = UIView(frame: CGRectMake(0, 0, wnd!.frame.size.width, wnd!.frame.size.height))
wnd!.addSubview(v);
v.backgroundColor = UIColor.whiteColor()
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(1.0)
v.alpha = 0.0;
UIView.commitAnimations();
}
但是我不确定应该在哪里添加
UIView v
的移除代码(在动画结束时执行的某个事件上...但是如何实现?)。此外,我的转换正确吗?