I want to add sub view and remove with one tap. This is my code:
/* To add subview */
var testView: UIView = UIView(frame: CGRectMake(0, 0, 320, 56
You have to use the viewWithTag function to find the view with the given tag.
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
let touch = touches.anyObject() as UITouch
let point = touch.locationInView(self.view)
if let viewWithTag = self.view.viewWithTag(100) {
print("Tag 100")
viewWithTag.removeFromSuperview()
} else {
print("tag not found")
}
}