0

我有一个用户可以触摸的圆圈,当你触摸它时,它会改变大小,然后恢复到原来的大小以表明你触摸了它。我希望用户能够随心所欲地触摸它,无论它当前是否有动画。我更新了我的动画以使用UIViewAnimationOptionAllowUserInteraction允许我在动画期间触摸它的标志,但它的行为不像我预期的那样。

我想我需要以某种方式停止当前播放的动画,将大小重置为正常然后再次播放,这是否正确,如果是,我该怎么做?如果不是我该怎么办?

- (void)pop{
    [view.layer removeAllAnimations];

    [UIView animateWithDuration:0.2
                      delay:0.0
                    options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAllowUserInteraction // reverse back to original value
                 animations:^{
                     // scale down 20%
                     self.transform = CGAffineTransformMakeScale(0.8, 0.8);
                 } completion:^(BOOL finished) {
                     self.transform = CGAffineTransformMakeScale(1, 1);
                 }];
}
4

2 回答 2

0

确定这不是你想要的?当玩家点击和弹出被调用时,动画应该重新开始吗?

- (void)pop{
    self.transform = CGAffineTransformMakeScale(1, 1); // If you want the animation to start over you need to reset the size before staring it again
    [view.layer removeAllAnimations];

    [UIView animateWithDuration:0.2
                  delay:0.0
                options: options:UIViewAnimationOptionAutoreverse  | UIViewAnimationOptionCurveEaseOut| UIViewAnimationOptionAllowUserInteraction // reverse back to original value
             animations:^{
                 // scale down 20%
                 self.transform = CGAffineTransformMakeScale(0.8, 0.8);
             } completion:^(BOOL finished) {
                 self.transform = CGAffineTransformMakeScale(1, 1);
             }];
}
于 2013-11-09T13:39:03.830 回答
0
self.btn = [[UIButton alloc] initWithFrame:CGRectMake(200, 200, 100, 30)];
[self.btn addTarget:self action:@selector(tapDown:) forControlEvents:UIControlEventTouchDown];
[self.btn addTarget:self action:@selector(tapUp:) forControlEvents:UIControlEventTouchUpInside];


- (IBAction)tapDown:(id)sender
{
    [UIView animateWithDuration:0.2
                          delay:0.0
                        options: UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAllowUserInteraction
                     animations:^{
                         // scale down 20%
                         self.btn.transform = CGAffineTransformMakeScale(0.8, 0.8);
                     } completion:nil];
}


- (IBAction)tapUp:(id)sender {
    [UIView animateWithDuration:0.2
                          delay:0.0
                        options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAllowUserInteraction // reverse back to original value
                     animations:^{
                         // scale up to 100%
                         self.btn.transform = CGAffineTransformMakeScale(1, 1);
                     } completion:nil];
}
于 2013-11-09T13:25:38.223 回答