【问题标题】:animation of uiimageView stopsuiimageView 的动画停止
【发布时间】:2011-07-24 12:15:22
【问题描述】:

这就是我想做的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 秒调用一次 但它不起作用,没有错误,但是当“imageView”在 2 秒后创建时,它会移动并转到已创建的新“imageView”的相同方向。我该如何解决这个问题?对不起我的英语我是法国人:/

【问题讨论】:

    标签: iphone xcode animation uiimageview


    【解决方案1】:

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

    在您定义imageViewArray 的地方,还将xArrayyArray 定义为NSMutableArrays。然后在-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);
    }
    

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

    【讨论】:

    • 看这一行:imageView.center = CGPointMake(imageView.center.x + X, imageView.center.y + Y); X 和 Y 是从哪里来的? -onTimer 方法。但是只有一个 X 和一个 Y,所以每次设置它们时,都会覆盖之前的值。
    • 它不起作用,我不知道为什么。我使用你的代码在 .h 中初始化 xArray 和 yArray 并查看 didLoad
    • 你必须比“它不起作用”更具体。
    • 屏幕上没有imageView的图像没有显示imageView
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-15
    • 1970-01-01
    相关资源
    最近更新 更多