[英]UILongPressGestureRecognizer sending action twice
我的長按手勢識別器導致其動作事件被執行兩次 ?
我試圖找出一個Warning: Attempt to present VC2 on VC1 whose view is not in the window hierarchy!
通過使用一些println()測試,我發現我的VC2被呈現兩次。
我的VC2演示方法:
P1long:UILongPressGestureRecognizer位於VC1的MainView上
在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會兩次表演。
您應該處理長按手勢識別器的狀態。 UILongPressGestureRecognizer的動作調用它的狀態變化。 所以你第一次收到state == UIGestureRecognizerStateBegan,第二次收到它的UIGestureRecognizerStateEnded。
你需要這樣的東西:
if (recognizer.state == UIGestureRecognizerStateEnded)
{
//your action
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.