创建图像后的动画问题

发布于 2024-11-25 11:56:37 字数 711 浏览 0 评论 0原文

大家好,这里是我的代码:

-(void) onTimer {
UIImage * image = [UIImage imageNamed:@"abouffer_03.png"];
imageView = [[UIImageView alloc] initWithImage: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;

}

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

}

“onTimer”每 4 秒调用一次,并且“onTimer2”上有一个 CADisplayLink (60fps)。

我的问题是每次调用“onTimer”时“imageView”的动画都会停止;创建一个新的“imageView”,然后 imageView 使用“onTimer2”方法移动,然后停止并创建另一个“imageView”...

我想要的是“imageView”的动画继续并同时创建新的“imageView” ,请问我该怎么做?抱歉我的英语我是法国人:/

Hi every one here is my code :

-(void) onTimer {
UIImage * image = [UIImage imageNamed:@"abouffer_03.png"];
imageView = [[UIImageView alloc] initWithImage: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;

}

-(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 :/

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

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

发布评论

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

评论(1

万劫不复 2024-12-02 11:56:37

您每次都使用相同的 imageView 对象来分配和初始化。您需要使用不同的imageView,例如:

-(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;

}

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;

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