0

我想为 ImageView 的 X 位置设置动画,并在它达到某个 X 位置时将其重置。例如,从 700 开始,然后向左移动。如果达到 100,我想将其重置为 700。并且不断地反复执行此操作。

很确定需要一个计时器,但不确定如何去做,因为这是我的第一个 IOS 应用程序。谷歌搜索发现了很多动画的东西,但都是不同的,这导致了混乱。:)

4

2 回答 2

0

请参阅此处如何使用 UIView 动画iPhone UIView 动画最佳实践或者设置一个计时器循环,然后调整视图的框架/中心

于 2013-04-28T19:48:45.100 回答
0

使用此代码

调用 [self animate:your_image_view];

    - (void)animate:(UIImageView*)your_image
    {
       if (need_to_animate)
       {
        CGRect from = CGRectMake(10, 100, 200, 200);
        CGRect to = CGRectMake(10, 700, 200, 200);

            [UIView animateWithDuration:2 animations:^{

                your_image.frame = from;

            } completion:^(BOOL finished) {

                your_image.frame = to;


                [UIView animateWithDuration:2 animations:^{

                    your_image.frame = from;

                } completion:^(BOOL finished) {

                    [self animate:your_image];

                }];

            }];
        }
    }
于 2013-04-28T19:53:09.063 回答