My Long Press Gesture Recognizer is causing its action event to be executed twice ?
I was trying to figure out a Warning: Attempt to present VC2 on VC1 whose view is not in the window hierarchy!
By using some println() tests, I found that my VC2 is being presented twice.
My VC2 presentation method:
P1long:UILongPressGestureRecognizer located on VC1's MainView
When long press done on P1
of VC1
@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() }
}
Console output:
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!
Why is my LongPress acting twice.
You should handle long press gesture recognizer's state. UILongPressGestureRecognizer's action invokes on it's state changes. So you are receiving it first time when state == UIGestureRecognizerStateBegan and second time when its UIGestureRecognizerStateEnded.
You need something like:
if (recognizer.state == UIGestureRecognizerStateEnded)
{
//your action
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.