[問題]gesture recognizer while UIView animate

看板MacDev作者 (史派克)時間11年前 (2013/10/30 09:59), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
請問有辦法在 UIView animateWithDuration的時候觸發 gesture recognizer 的event嗎? 舉例來說: 我有一個 UIImageView 使用UIView animate的方法從螢幕左邊移動到右邊 但是我希望在移動中的同時可以接收到gesture recognizer的event 下面是我實驗失敗的code,每次都要等球移動完後才有辦法觸發recognizer的event。 想請問有沒有其他方法讓球在移動的同時又可以被drag呢? 謝謝。 Code example: -(void)addBall{ UIImageView *ball = [[UIImageView alloc]initWithFrame:CGRectMake(0,50,50,50)]; [self addLongPressRecognizer:ball]; [UIView animateWithDuration:10 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ [ball setFrame:CGRectMake(1024,50,50,50)]; } completion:nil]; } - (void)addLongPressRecognizer:(UIView *)target { UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; longPressGestureRecognizer.delegate = self; longPressGestureRecognizer.minimumPressDuration = .001; [target addGestureRecognizer:longPressGestureRecognizer]; target.userInteractionEnabled = YES; } - (void)handleLongPress:(UIPanGestureRecognizer *)gestureRecognizer { UIView *ball = gestureRecognizer.view; [ball.layer removeAllAnimations]; CGPoint point = [gestureRecognizer locationInView:self.view]; if (gestureRecognizer.state == UIGestureRecognizerStateChanged) { ball.center = point; } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 24.90.213.192
文章代碼(AID): #1IS6WITK (MacDev)
文章代碼(AID): #1IS6WITK (MacDev)