gpt4 book ai didi

ios - 我可以使用 setAnimationRepeatCount : within a UIView animation block?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:24:19 26 4
gpt4 key购买 nike

我想使用 UIAnimation 的 block 样式方法使按钮闪烁,特别是:

animateWithDuration:delay:options:animations:completion

我认为我需要设置的一件事是“AnimationRepeatCount”属性 - 可以像这样在动画 block 代码中设置它吗?

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

在基于 block 的调用之前,我原来的方法是这样的:

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

最佳答案

是的,您可以将它设置在 block 内,它会按照您的预期进行。

关于ios - 我可以使用 setAnimationRepeatCount : within a UIView animation block?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8595907/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com