ios - 循环动画 - 不去
<p><p>我试图在一个循环内重复一系列动画,在每个循环中随机更改一些参数。这是代码。请问有人知道为什么它不起作用吗?
如果我用按钮操作调用它一次,它可以工作,但循环它不会。
非常感谢!朱塞佩</p>
<pre><code>-(IBAction)startLoop:(id)sender {
for (int i=1;i<10; i++) {
;
}
}
-(id) animation2 {
int max=500;
UIImage *myImage = ;
CALayer *myLayer = ;
myLayer.contents = (id)myImage.CGImage;
myLayer.bounds = CGRectMake(0, 0, 50, 60);
;
;
;
//translation1
CGPoint startPt = CGPointMake(arc4random()%(max),arc4random()%(max));
CGPoint endPt = CGPointMake(arc4random()%(max),arc4random()%(max));
CABasicAnimation *transl1 = ;
transl1.removedOnCompletion = FALSE;
transl1.timingFunction = ;
transl1.fromValue = ;
transl1.toValue = ;
transl1.duration = 2.0;
transl1.fillMode = kCAFillModeForwards;
transl1.beginTime = 0;
//scale 1
CABasicAnimation *scale1 = [CABasicAnimation
animationWithKeyPath:@"transform.scale"];
scale1.removedOnCompletion = FALSE;
];
;
scale1.fillMode = kCAFillModeForwards;
scale1.beginTime = 0;
//rotation1
CABasicAnimation *rotation1 = [CABasicAnimation
animationWithKeyPath:@"transform.rotation.z"];
rotation1.removedOnCompletion = FALSE;
;
;
//rotation1.repeatCount = HUGE_VALF;
;
rotation1.fillMode = kCAFillModeForwards;
rotation1.beginTime = 0;
//group
CAAnimationGroup* group = ;
;
group.removedOnCompletion = FALSE;
group.fillMode = kCAFillModeForwards;
];
;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您的代码不会重复注释 10 次,而是立即启动 10 个动画。如果您的目标是在前一个动画结束后开始动画,您应该尝试使用 <code>NSTimer</code>。 </p></p>
<p style="font-size: 20px;">关于ios - 循环动画 - 不去,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/10479949/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/10479949/
</a>
</p>
页:
[1]