我想添加子视图并一键删除。这是我的代码:
/ *添加子视图* /
var testView: UIView = UIView(frame: CGRectMake(0, 0, 320, 568))
testView.backgroundColor = UIColor.blueColor()
testView.alpha = 0.5
testView.tag = 100
super.view.userInteractionEnabled = false
self.view.userInteractionEnabled = true
self.view.addSubview(testView)
/ *删除子视图* /
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
let touch = touches.anyObject() as UITouch
let point = touch.locationInView(self.view)
if(testView.tag==100){
println("Tag 100")
testView.removeFromSuperview()
}
else{
println("tag not found")
}
}
但是删除它不起作用有人可以帮助我吗?谢谢!