减慢正在移动图像视图的循环

时间:2012-06-28 16:19:03

标签: objective-c cocoa-touch while-loop

当我称这种方法时:

- (void)method:(int)i {
    while (image[i].center.y <= 100) {
        image[i].center = CGPointMake(image[i].center.x, image[i].center.y+2);
    }
}

循环立即运行,图像立即变为y = 100的点。有没有办法减慢这个(或者我不知道的另一种选择),让图像在视觉上移动或加速到点而不是立即移动到它?

2 个答案:

答案 0 :(得分:7)

好像你正在制作动画,也许是这样的。

- (void)method:(int)i {
   [UIView animateWithDuration:2.0
                    animations:^{ 
                      image[i].center = CGPointMake(image[i].center.x, 100);
                    }];
}

我建议你阅读这个

http://developer.apple.com/library/ios/#documentation/windowsviews/conceptual/viewpg_iphoneos/animatingviews/animatingviews.html

答案 1 :(得分:2)

尝试使用与此类似的代码:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
image.center = CGPointMake(image.center.x, image.center.y-moveAmount);
[UIView commitAnimations];