我可以在 UIView 动画块中使用 setAnimationRepeatCount: 吗?
Posted
技术标签:
【中文标题】我可以在 UIView 动画块中使用 setAnimationRepeatCount: 吗?【英文标题】:Can I use setAnimationRepeatCount: within a UIView animation block? 【发布时间】:2011-12-21 20:25:32 【问题描述】:我想使用 UIAnimation 的块样式方法使按钮闪烁,特别是:
animateWithDuration:delay:options:animations:completion
我认为我需要设置的一件事是“AnimationRepeatCount”属性 - 可以像这样在动画块代码中设置吗?
- (void)animateItemWithBlinking:(BOOL)blinking
__block BOOL isInBlinkState = blinking;
if (!isBlinking)
// Start blinking
[UIView animateWithDuration:0.50f
delay:0
options:UIViewAnimationCurveLinear
animations:^
// Can I call the AnimationRepeat setter here or
// should it be elsewhere outside this block?
[UIView setAnimationRepeatCount:1000];
[UIView setAnimationRepeatAutoreverses:YES];
[button setAlpha:0.0f];
completion:^(BOOL finished)
// eventually, this is a value that I want the method to return
isInBlinkState = !isInBlinkState;
];
else
// Stop blinking
[UIView animateWithDuration:0.30f
delay:0
options:UIViewAnimationOptionAllowUserInteraction
animations:^
// Stop blinking - reset everything
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationRepeatCount:1];
[button setAlpha:1.0f];
completion:^(BOOL finished)
// eventually, this is a value that I want the method to return
isInBlinkState = !isInBlinkState;
];
在基于块的调用之前,我原来的方法是这样的:
- (void)animateItemWithBlinking:(BOOL) blinking
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.50f];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
if( !blinking )
// Start it
[UIView setAnimationRepeatCount:1000];
[UIView setAnimationRepeatAutoreverses:YES];
[button setAlpha:0.0f];
else
// Stop it
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationRepeatCount:1];
[button setAlpha:1.0f];
blinking = !blinking;
[UIView commitAnimations];
【问题讨论】:
你可以看看这个和你类似的问题。 ***.com/questions/4069758/… 【参考方案1】:是的,您可以将它设置在块内,它会按照您的预期进行。
【讨论】:
以上是关于我可以在 UIView 动画块中使用 setAnimationRepeatCount: 吗?的主要内容,如果未能解决你的问题,请参考以下文章
android界面切换增加了animation特效,但是没有实现动画效果(已经执行到setAni