0
在這裏,我添加一個子視圖到我的SuperView:選擇它時,通過點擊上海華刪除子視圖
@IBAction func tapRecognizerAction(_ sender: UITapGestureRecognizer) {
let location = sender.location(in: self.view)
addNew(x: location.x, y: location.y)
}
func addNew(x : CGFloat, y : CGFloat){
let testView: CustomView = CustomView(frame: CGRect(x: x, y: y, width: 50, height: 50))
testView.backgroundColor = .blue
testView.isUserInteractionEnabled = true
self.view.addSubview(testView)
let aSelector : Selector = #selector(PlanViewController.removeSubview)
let tapGesture = UITapGestureRecognizer(target:self, action: aSelector)
testView.addGestureRecognizer(tapGesture)
}
func removeSubview(){
}
如何刪除特定的子視圖,當我觸摸它。