我的长按手势识别器导致其动作事件执行两次 ?
我试图找出Warning: Attempt to present VC2 on VC1 whose view is not in the window hierarchy!
通过使用一些println()测试,我发现我的VC2被呈现了两次。
我的VC2演示方法:
P1long:位于VC1主视图上的UILongPressGestureRecognizer
在VC1的P1
上长按
@IBAction func PresentPlayerInfo(sender: UIGestureRecognizer){
var loc = sender.locationInView(self.view)
var segueSwitch = 0
if (CGRectContainsPoint(self.P1.frame, lock))
{ tappedView = self.P1; segueSwitch = 1 }
else if (CGRectContainsPoint(self.ReDeal.frame, lock))
{ tappedView = self.ReDeal; segueSwitch = 2 }
if segueSwitch == 1
{ performSegueWithIdentifier("PlayersTable", sender: self)
println("PlayersTable") }
else if segueSwitch == 2
{ self.viewDidLoad() }
}
控制台输出:
PlayersTable
PlayersTable
Warning: Attempt to present <iPro_Poker_HH_swift.VC2: 0x14555470> on <iPro_Poker_HH_swift.VC1: 0x153a2600> whose view is not in the window hierarchy!
为什么我的LongPress会两次表演。
答案 0 :(得分:3)
你应该处理长按手势识别器的状态。 UILongPressGestureRecognizer的动作会调用它的状态变化。所以你第一次收到state == UIGestureRecognizerStateBegan,第二次收到它的UIGestureRecognizerStateEnded。
您需要以下内容:
if (recognizer.state == UIGestureRecognizerStateEnded)
{
//your action
}