1

使用简单CGAffineTransformMakeScale的脉冲标签,尝试在第二个块上应用缓和选项、延迟等时出现错误?没有这个,我会得到生涩的动画,因为我在增加时得到缓解,而在恢复到原始大小时没有

  [UIView animateWithDuration:1.0f delay:0 options: UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations: ^{

[UIView setAnimationRepeatCount:10];

    self.transform = CGAffineTransformMakeScale(1.1,1.1);

} completion:^(BOOL finished) {


    [UIView animateWithDuration:1.0 animations:^{  // <<< "No known method for selector" error here if I add options

        self.transform = CGAffineTransformMakeScale(1.0,1.0);

    }];
}];
4

2 回答 2

1

如果你想让它动画十次然后停止,你可以使用UIViewAnimationOptionRepeatandUIViewAnimationOptionAutoreverse选项。这样,它会在重复之前优雅地恢复到原来的状态。它还使您无需在最后对其进行动画处理:

[UIView animateWithDuration:1.0
                      delay:0.0
                    options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction
                 animations:^{
                     [UIView setAnimationRepeatCount:10];
                     self.viewToResize.transform = CGAffineTransformMakeScale(1.1, 1.1);
                 }
                 completion:^(BOOL finished) {
                     self.viewToResize.transform = CGAffineTransformIdentity;
                 }];
于 2013-06-20T00:05:00.797 回答
0

不要像那样链接动画。使用较低级别的 CoreAnimation API 来指定带有关键帧的动画。这是一个模仿 UIAlertView 在屏幕上显示方式的示例:

CAKeyframeAnimation* bounceAnim = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
bounceAnim.duration = 0.4f;
bounceAnim.values = @[ @0.01f, @1.1f, @0.9f, @1.f ];
bounceAnim.keyTimes = @[ @0.f, @0.5f, @0.75f, @1.f ];
bounceAnim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
bounceAnim.fillMode = kCAFillModeBoth;
bounceAnim.removedOnCompletion = YES;

[dialog.layer addAnimation:bounceAnim forKey:@"bounce"];

您需要修改它以使其循环,还可以根据自己的喜好调整值和时间。查看CAKeyframeAnimation文档。

于 2013-06-19T22:45:45.330 回答