gpt4 book ai didi

iphone - for循环中的UIButton翻转动画

转载 作者:行者123 更新时间:2023-11-28 20:43:57 24 4
gpt4 key购买 nike

我的代码如下,

int i;
for (i=1; i < 13; i++ ){
UIButton * myButton1 = (UIButton *)([self.view viewWithTag:i]);
NSString *imageLoop2=[NSString stringWithFormat:@"%@",[arr1 objectAtIndex:i-1]];

[UIView beginAnimations:@"Flip" context:NULL];
[UIView setAnimationDuration:0.60];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:myButton1 cache:NO];
myButton1.userInteractionEnabled = NO;
myButton1.alpha=1.0f;
[myButton1 setBackgroundImage:[UIImage imageNamed:imageLoop2] forState:UIControlStateNormal];

[UIView commitAnimations];

}

它会在相同的时间内翻转所有按钮。
但我的问题是它在一个接一个地翻转时出现“第一个按钮完成翻转动画然后第二个按钮开始翻转”

请给我建议。

谢谢

最佳答案

在同一个 block 中一个接一个地做动画。尝试[UIView setAnimationDelay:delay];

还要记住,2 block 或单 block 动画是在后台线程中执行的。所以有了这个改变 -

int i;
[UIView beginAnimations:@"Flip" context:NULL];
[UIView setAnimationDelegate:self];
float delay = 0;
float duration = 0.6;

for (i=1; i < 13; i++ ){
UIButton * myButton1 = (UIButton *)([self.view viewWithTag:i]);
NSString *imageLoop2 = [NSString stringWithFormat:@"%@",[arr1 objectAtIndex:i-1]];

[UIView setAnimationDelay:delay];
[UIView setAnimationDuration:duration];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:myButton1 cache:NO];
myButton1.userInteractionEnabled = NO;
myButton1.alpha=1.0f;
[myButton1 setBackgroundImage:[UIImage imageNamed:imageLoop2] forState:UIControlStateNormal];
delay = delay + duration;

}
[UIView commitAnimations];

此外,Apple Docs 表示,与您正在执行的 2 block 动画相比,单 block 动画在性能方面更加流畅。只是一个想法...

关于iphone - for循环中的UIButton翻转动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7228171/

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