uiimageView动画的问题:动画停止
这是我的代码:
-(void) createNewBall {
UIImage * image = [UIImage imageNamed:@"bulle_03.png"];
bulleBouge = [[UIImageView alloc] initWithImage:image];
[bulleBouge setCenter:[self randomPointSquare]];
[[self view] addSubview:bulleBouge];
}
-(void)moveTheBall{
bulleBouge.center = CGPointMake(imageView.center.x + X, imageView.center.y + Y);
}
每两秒调用一次createNewBall
。我的问题是,创建的每个 bulleBouge
都会在两秒后停止移动。我不知道为什么。
请问我该如何解决这个问题?
Here is my code:
-(void) createNewBall {
UIImage * image = [UIImage imageNamed:@"bulle_03.png"];
bulleBouge = [[UIImageView alloc] initWithImage:image];
[bulleBouge setCenter:[self randomPointSquare]];
[[self view] addSubview:bulleBouge];
}
-(void)moveTheBall{
bulleBouge.center = CGPointMake(imageView.center.x + X, imageView.center.y + Y);
}
createNewBall
is called every two seconds. My problem is that every bulleBouge
that is created stops moving after two seconds. I don't know why.
How can I solve this please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它停止移动 b/cu 每两秒初始化一次新的 bulleBouge。您还会泄漏内存,因为在为其分配新值之前从未释放它。所以发生的情况是,在创建 imageView 之后,您只保留对最后一个实例的引用,因此只有最后一个实例正在改变位置。要解决此问题,请将所有新的 uiImageView 存储在一个数组中,并在两秒后随机移动它们。
It stops moving b/c u are initializing new bulleBouge every two seconds. You are also leakin memory since you never releasy it before assigning new value to it. so what happens is that after u create the imageView you only keep the reference to the lasts instance, hence only the last one is changing position. To fix this store all your new uiImageViews in an array and move them randomly after two seconds.
西普里安是正确的。在更简单的形式中,您每两秒在同一变量下创建一个新的 bulleBouge。该程序已经有一个,但由于您告诉它在同一 ivar 下创建一个新的,它会忘记旧的,因此不会移动它。您需要一个数组,以便可以单独记住每个球,从而单独移动,如他发布的示例代码所示。
Cyprian is correct. In a simpler form, you're creating a new bulleBouge every two seconds, under the same variable. The program already has one, but since you told it to make a new one under the same ivar it forgets the old one, and thus doesn't move it. You need an array so that each ball can be remembered separately, and thus moved separately as seen in the example code that he posted.