uiimageView 的动画停止

发布于 2024-11-26 07:30:06 字数 1114 浏览 1 评论 0原文

这就是我想做的http://www.youtube.com/watch?v=rD3MTTPaK98 这是我的代码:

-(void) onTimer {


UIImage * image = [UIImage imageNamed:@"abouffer_03.png"];
imageView = [[UIImageView alloc] initWithImage:image];

[imageView setCenter:[self randomPointSquare]];

 [imageViewArray addObject:imageView];

[[self view] addSubview:imageView];

[imageView release];

ix=imageView.center.x;
iy=imageView.center.y;

X=(240-ix)/230;
Y=(160-iy)/230;
coteA=(240-ix);
coteB=(160-iy);
angleDeRotation=atan(coteB/coteA);
if(ix>250||0>iy>320){
    imageView.transform = CGAffineTransformMakeRotation(angleDeRotation+3.14);
}
else{
imageView.transform = CGAffineTransformMakeRotation(angleDeRotation);
}
}



-(void)onTimer2{
for(int i=0; i< [imageViewArray count];i++){
    imageView = [imageViewArray objectAtIndex:i];
    imageView.center = CGPointMake(imageView.center.x + X, imageView.center.y + Y);
}

onTimer 每 2 秒调用一次 但它不起作用,没有错误,但是当 2 秒后创建“imageView”时,它会停止移动并转到已创建的新“imageView”的相同方向。我该如何解决这个问题?抱歉我的英语我是法国人:/

here is what I wanna do http://www.youtube.com/watch?v=rD3MTTPaK98
and here is my code:

-(void) onTimer {


UIImage * image = [UIImage imageNamed:@"abouffer_03.png"];
imageView = [[UIImageView alloc] initWithImage:image];

[imageView setCenter:[self randomPointSquare]];

 [imageViewArray addObject:imageView];

[[self view] addSubview:imageView];

[imageView release];

ix=imageView.center.x;
iy=imageView.center.y;

X=(240-ix)/230;
Y=(160-iy)/230;
coteA=(240-ix);
coteB=(160-iy);
angleDeRotation=atan(coteB/coteA);
if(ix>250||0>iy>320){
    imageView.transform = CGAffineTransformMakeRotation(angleDeRotation+3.14);
}
else{
imageView.transform = CGAffineTransformMakeRotation(angleDeRotation);
}
}



-(void)onTimer2{
for(int i=0; i< [imageViewArray count];i++){
    imageView = [imageViewArray objectAtIndex:i];
    imageView.center = CGPointMake(imageView.center.x + X, imageView.center.y + Y);
}

onTimer is called every 2 seconds
but it doesn't work, there is no error but when a "imageView" is created after 2 seconds it sop moving and go to the same direction of the new " imageView" that has been created. How can I solve this ? sorry for my english I'm french :/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゞ花落谁相伴 2024-12-03 07:30:06

您将 X 和 Y 添加到所有图像视图中,但它始终是最后计算的值。创建 X 和 Y 值数组并使用与图像视图对应的值。

在定义imageViewArray的地方,还要将xArrayyArray定义为NSMutableArray。然后在 -onTimer 中,当您设置 X 和 Y 时,执行以下操作:

[xArray addObject:[NSNumber numberWithFloat:X]];
[yArray addObject:[NSNumber numberWithFloat:Y]];

最后,在 -onTimer2 中,执行以下操作:

-(void)onTimer2{
for(int i=0; i< [imageViewArray count];i++) {
    float localX = [(NSNumber *)[xArray objectAtIndex:i] floatValue];
    float localY = [(NSNumber *)[yArray objectAtIndex:i] floatValue];

    imageView = [imageViewArray objectAtIndex:i];
    imageView.center = CGPointMake(imageView.center.x + localX, imageView.center.y + localY);
}

这将使用您设置的 X 和 Y 的值在-onTimer中。

You’re adding X and Y to all of your image views, but it’a always the last-computed value. Make an array of X and Y values and use the value that corresponds with your image view.

Where you define imageViewArray, also define xArray and yArray as NSMutableArrays. Then in -onTimer, when you set X and Y, do this:

[xArray addObject:[NSNumber numberWithFloat:X]];
[yArray addObject:[NSNumber numberWithFloat:Y]];

Finally, in -onTimer2, do this:

-(void)onTimer2{
for(int i=0; i< [imageViewArray count];i++) {
    float localX = [(NSNumber *)[xArray objectAtIndex:i] floatValue];
    float localY = [(NSNumber *)[yArray objectAtIndex:i] floatValue];

    imageView = [imageViewArray objectAtIndex:i];
    imageView.center = CGPointMake(imageView.center.x + localX, imageView.center.y + localY);
}

That will use the value of X and Y that you set in -onTimer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文