当我启用UIPanGestureRecognizer时,我会禁用按下的按钮的动作,然后当手势结束时我想重新启用动作
func pan(rec:UIPanGestureRecognizer) {
var p:CGPoint = rec.locationInView(self.view)
var center:CGPoint = CGPointZero
switch rec.state {
case .Began:
println("began")
selectedView = view.hitTest(p, withEvent: nil)
if selectedView != nil {
self.view.bringSubviewToFront(selectedView!)
}
case .Changed:
if let buttonRecognize = rec.view as? UIButton {
button.removeTarget(self, action: Selector("\(title):"), forControlEvents:UIControlEvents.TouchUpInside) // but this disable all
case .Ended:
println("ended")
if let subview = selectedView {
if let button = rec.view as? UIButton {
if let title = button.titleForState(.Normal){
button.addTarget(self, action: Selector("\(title):"), forControlEvents: UIControlEvents.TouchUpInside)
selectedView = nil
}}
}
case .Possible:
println("possible")
case .Cancelled:
println("cancelled")
case .Failed:
println("failed")
}}}
}
我试过这种方式,我重新激活了动作,但不知道如何只删除按下按钮的动作?
答案 0 :(得分:0)
您可以设置button.enabled = false
,而不是删除按钮的目标操作。