使用简单的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);
}];
}];
答案 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)
如果您希望它动画十次然后停止,您可以使用UIViewAnimationOptionRepeat
和UIViewAnimationOptionAutoreverse
选项。这样,它会在重复之前优雅地将自身反转回原始状态。它还可以使您无需在最后设置动画:
[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;
}];