块动画延迟不起作用
当第一次调用这个方法时,效果很好。
第二次调用时,延迟不起作用。
除了延迟之外,其他代码运行良好。
我该如何解决这个问题?
-(void)makeParticle:(id)sender{
Bubble *bubble=(Bubble*)sender;
CGPoint center=bubble.center;
NSInteger radian=arc4random()%360;
for (int i=1; i<=13; i++) {
NSInteger distance=20+arc4random()%80;
radian+=10+arc4random()%40;
UIImageView *iv=[[[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"star%i.png",i]]]autorelease];
NSInteger size=20+arc4random()%20;
iv.frame=CGRectMake(0, 0, size, size);
iv.center=center;
iv.alpha=0;
[self addSubview:iv];
[iv release];
[UIView animateWithDuration:0.4 delay:0.1 options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^(void) {
iv.alpha=0.5;
iv.center=CGPointMake(center.x+distance*cos(radian), center.y+distance*sin(radian));
} completion:^(BOOL finished) {
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^(void) {
iv.center=CGPointMake(600, 100);
iv.alpha=0;
} completion:^(BOOL finished) {
[iv removeFromSuperview];
}];
}];
}
}
When this method is first called, it works good.
On second call, the delay does not work.
The other code works good except for the delay.
How do I solve this problem?
-(void)makeParticle:(id)sender{
Bubble *bubble=(Bubble*)sender;
CGPoint center=bubble.center;
NSInteger radian=arc4random()%360;
for (int i=1; i<=13; i++) {
NSInteger distance=20+arc4random()%80;
radian+=10+arc4random()%40;
UIImageView *iv=[[[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"star%i.png",i]]]autorelease];
NSInteger size=20+arc4random()%20;
iv.frame=CGRectMake(0, 0, size, size);
iv.center=center;
iv.alpha=0;
[self addSubview:iv];
[iv release];
[UIView animateWithDuration:0.4 delay:0.1 options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^(void) {
iv.alpha=0.5;
iv.center=CGPointMake(center.x+distance*cos(radian), center.y+distance*sin(radian));
} completion:^(BOOL finished) {
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^(void) {
iv.center=CGPointMake(600, 100);
iv.alpha=0;
} completion:^(BOOL finished) {
[iv removeFromSuperview];
}];
}];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论