【问题标题】:Slowing down a while loop that is moving an image view减慢正在移动图像视图的 while 循环
【发布时间】:2012-06-28 16:19:03
【问题描述】:

当我调用这个方法时:

- (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 的位置。有没有办法减慢这个速度(或者我不知道的替代方法),让图像在视觉上移动或加速到某个点,而不是立即移动到那个点?

【问题讨论】:

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


    【解决方案1】:

    您似乎正在寻找制作动画,可能是这样的。

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

    【讨论】:

      【解决方案2】:

      尝试使用类似这样的代码:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-04-07
        • 1970-01-01
        • 1970-01-01
        • 2021-11-24
        • 2023-04-03
        • 2016-09-03
        • 1970-01-01
        相关资源
        最近更新 更多