开发者

Problem with the animation of images after their creation

Hi every one here is my code :

-(void) onTimer {
UIImage * image = [UIImage imageNamed:@"abouffer_03.png"];
imageView = [[UIImageView alloc] initWithImage:image];
[imageView setCenter开发者_C百科:[self randomPointSquare]];
[[self view] addSubview:imageView];

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

X=(240-ix)/230;
Y=(160-iy)/230;

}

-(void)onTimer2{
imageView.center = CGPointMake(imageView.center.x + X, imageView.center.y + Y);

}

"onTimer" is called every 4 seconds and there is a CADisplayLink (60fps) on "onTimer2".

My problem is that "imageView"'s animation stops every time "onTimer" is called; a new "imageView" is created then imageView move with "onTimer2" method then it stops and another "imageView" is created ...

What I want is that "imageView"'s animation continues and in parallel new "imageView"s are created, how can I do this please ? sorry for my english I'm french :/


You are using same imageView object to alloc and initialize every time. You need to use different imageView, like:

-(void) onTimer {
    UIImage * image = [UIImage imageNamed:@"abouffer_03.png"];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:<specify desired frame>];
    imageView.image = image;
    [imageView setCenter:[self randomPointSquare]];
    [[self view] addSubview:imageView];

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

    X=(240-ix)/230;
    Y=(160-iy)/230;

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜