objective c - Long press gesture get called twice when Alert view is shown -
i'm having troubles long press gesture here. i've around , found post related issues, no luck until now.
i have long press gesture view, , want show alert view when gesture trigger, somehow trigger got called twice when alert view shown, i've check state of gesture recognizer still no luck. here code:
initial code:
uilongpressgesturerecognizer *longtap = [[uilongpressgesturerecognizer alloc] initwithtarget:self action:@selector(handletapgesture:)]; [longtap setminimumpressduration:1]; [self addgesturerecognizer:longtap]; - (ibaction)handletapgesture:(uipangesturerecognizer*)sender { if (sender.state == uigesturerecognizerstatechanged) { nslog(@"change"); } else if (sender.state == uigesturerecognizerstateended) { nslog(@"ended"); } else { nslog(@"begin"); uialertview *alert = [[uialertview alloc] initwithtitle:@"long pressed" message:nil delegate:nil cancelbuttontitle:@"ok" otherbuttontitles: nil]; [alert show]; //if remove line, trigger call once. } }
the wierd thing is, if remove [alert show], goes expected, gesture trigger once. has explanation this? in advance.
please use below code solution.
uilongpressgesturerecognizer *longtap = [[uilongpressgesturerecognizer alloc] initwithtarget:self action:@selector(handletapgesture:)]; [longtap setminimumpressduration:1]; longtap.delegate = (id)self; [self.view addgesturerecognizer:longtap]; - (void)handletapgesture:(uilongpressgesturerecognizer *)sender { if (sender.state == uigesturerecognizerstatechanged) { nslog(@"change"); } else if (sender.state == uigesturerecognizerstateended) { nslog(@"ended"); } else if (sender.state == uigesturerecognizerstatebegan) { nslog(@"begin"); uialertview *alert = [[uialertview alloc] initwithtitle:@"long pressed" message:nil delegate:nil cancelbuttontitle:@"ok" otherbuttontitles: nil]; [alert show]; //if remove line, trigger call once. } }
Comments
Post a Comment