动画选项未被尊重/第二个动画块中的错误

时间:2013-06-19 22:34:29

标签: ios objective-c cocoa-touch objective-c-blocks

使用简单的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);

    }];
}];

2 个答案:

答案 0 :(得分: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文档。

答案 1 :(得分:0)

如果您希望它动画十次然后停止,您可以使用UIViewAnimationOptionRepeatUIViewAnimationOptionAutoreverse选项。这样,它会在重复之前优雅地将自身反转回原始状态。它还可以使您无需在最后设置动画:

[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;
                 }];