Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 图像创建后的动画问题_Iphone_Animation_Timer_Uiimageview - Fatal编程技术网

Iphone 图像创建后的动画问题

Iphone 图像创建后的动画问题,iphone,animation,timer,uiimageview,Iphone,Animation,Timer,Uiimageview,大家好这里是我的代码: -(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

大家好这里是我的代码:

-(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”,然后使用“onTimer2”方法移动imageView,然后停止并创建另一个“imageView”


我想要的是“imageView”的动画继续,并同时创建新的“imageView”,请问我如何才能做到这一点?对不起,我的英语是法语:/

您每次都使用相同的
imageView
对象进行alloc和初始化。您需要使用不同的
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;

}
-(void)onTimer{
UIImage*image=[UIImage ImageName:@“aboutfer_03.png”];
UIImageView*imageView=[[UIImageView alloc]initWithFrame:];
imageView.image=图像;
[imageView设置中心:[自随机点方形]];
[[self view]addSubview:imageView];
ix=imageView.center.x;
iy=imageView.center.y;
X=(240 ix)/230;
Y=(160 iy)/230;
}

否问题仍然存在,imageView的动画每4秒停止一次使用不同的线程添加后续的imageView必须尝试简单的
[self-PerformanceSelectorInBackground:
方法并将ur-onTimer作为选择器传递。是的,但当我编写此[self-PerformanceSelectorInBackground:onTimer]时;我在Timer上有一个未声明的n错误我不知道为什么只是检查文档中此函数的定义…您需要传递一个选择器对象,而不是函数名。使用
@选择器(onTimer)
。从文档中获得帮助非常容易