Tôi muốn thêm chế độ xem phụ và xóa bằng một lần nhấn. Đây là mã của tôi:
/ * Để thêm lượt xem phụ * /
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)
/ * Để xóa lượt xem phụ * /
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")
}
}
Nhưng xóa nó không hoạt động Ai đó có thể giúp tôi không? Cảm ơn!