我写了下面的代码,使用NSTimer从顶部移动到按钮的图像。但是,当我运行它时,我无法单独获取图像。基本上,图像留下痕迹。我想要的是让图像逐帧移动。我错过了什么?iphone开发:动画与NSTimer
-(void)printOut:(NSTimer*)timer1;
{
image = [[UIImageView alloc] initWithFrame:CGRectMake(50, -50+m, 50, 50)];
[image setImage:[UIImage imageNamed:[NSString stringWithFormat:@"image.png"]]];
CGRect oldFrame = image.frame;
image.frame = CGRectMake(oldFrame.origin.x+5, oldFrame.origin.y, oldFrame.size.width, oldFrame.size.height);
[self.view addSubview:image];
m++;
if (m == 1000) {
[timer1 invalidate];
}
}
编辑:我不想使用动画。因为稍后我需要使用碰撞检测,并且不可能控制动画的坐标。
我无法理解你的query..canü请 – Rajneesh071
@ Rajneesh071好吧,当我运行这段代码的图像从屏幕顶部出现,并开始移动,但它不是一帧帧发生。我的意思是当新框架出现时,前一帧不会消失。希望它很清楚:/ – death7eater
UIImageView * image = [[UIImageView alloc] initWithFrame:CGRectMake(50,-50 + m,50,50)]; [image setImage:[UIImage imageNamed:[NSString stringWithFormat:@“image.png”]]]; [self.view addSubview:image]; – Rajneesh071