我正在尝试为一些 UIImageViews 设置动画以使用CADisplayLink
调用MoveObjects
函数来“跌倒”页面。然而,尽管函数调用的间隔是一致的 0.0155-0.017 秒,但动画似乎每隔几帧就会断断续续,就像我尝试使用 aNSTimer
调用函数时一样。有什么我做错了,导致口吃吗?
在viewDidLoad
:
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(gameLoop)];
displayLink.frameInterval=1;
[displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
当前 gameloop pnly 调用 UpdateObjects:
-(void)updateObjects{
timeStamp=[displayLink timestamp];
double frameTime=timeStamp-oldTime;
oldTime= timeStamp;
if (frameTime>10){
frameTime=0;
}
NSLog(@"%f",frameTime);
for (int i=0; i<objectsArray.count; i+=1) {
UIImageView *currentObject=[objectsArray objectAtIndex:i];
CGRect currentObjectFrame=[currentObject frame];
[currentObject setFrame:CGRectMake(CGRectGetMinX(currentObjectFrame), CGRectGetMinY(currentObjectFrame)+200*frameTime,CGRectGetWidth(currentObjectFrame) , CGRectGetHeight(currentObjectFrame))];
}
}