作者Spake (史派克)
看板MacDev
标题[问题]gesture recognizer while UIView animate
时间Wed Oct 30 09:59:44 2013
请问有办法在 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