我试图通过在视图加载后来回更改alpha级别来制作一个有图像的uibutton缓慢脉动...
目前我正在这样做,但它什么也没做......
-(void)loopdyloop
{
while ( myCount < 1000 )
{
[UIView animateWithDuration:3.0
delay:0.0f
options:UIViewAnimationCurveEaseOut
animations:^{
iconButton.alpha = 0.0;
} completion:^(BOOL finished) {
if (finished) {
NSLog(@"animated");
}
}];
[UIView animateWithDuration:3.0
delay:0.0f
options:UIViewAnimationCurveEaseOut
animations:^{
iconButton.alpha = 1.0;
} completion:^(BOOL finished) {
if (finished) {
NSLog(@"animated");
}
}];
myCount++;
}
}
从viewdidload方法
调用此方法非常原始我知道,但这是我最好的尝试,如果你对如何实现这一点有任何想法,我将不胜感激。
答案 0 :(得分:14)
如何在viewDidLoad
中的按钮图层中应用它:
CABasicAnimation *pulseAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
pulseAnimation.duration = .5;
pulseAnimation.toValue = [NSNumber numberWithFloat:1.1];
pulseAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pulseAnimation.autoreverses = YES;
pulseAnimation.repeatCount = FLT_MAX;
[YOURButton.layer addAnimation:pulseAnimation forKey:nil];
你可以尝试一下。
答案 1 :(得分:5)
如果你想让它永远重复,你可以将动画选项添加到自动反转和重复,如下所示:
[UIView animateWithDuration:3.0
delay:0.0f
options:UIViewAnimationCurveEaseOut |
UIViewAnimationOptionRepeat |
UIViewAnimationOptionAutoreverse
animations:^{
iconButton.alpha = 0.0;
}
completion:^(BOOL finished) {
// You could do something here
}];
它会使alpha首先动画为0.0,然后回到原始(1.0)然后反复做这两件事......