【问题标题】:How do I repeat this animation?我如何重复这个动画?
【发布时间】:2014-10-11 11:35:22
【问题描述】:

我有一个 UIImageView,它在视图加载时移动。 它首先会向上 +100,然后将 a BOOL 设置为已完成。

当 BOOL 设置为完成时,它将执行另一个动画,将 UIImageView 放回其原始位置。当我的 UIImageView 然后回到原来的位置时,它应该重新开始整个事情。这种重复应该永远持续下去!我该怎么做?

这是我的代码:

[UIView animateWithDuration:0.5
     animations:^

     {
         //move up
         Person.center = CGPointMake(Person.center.x, Person.center.y +100);

     }
                     completion:^(BOOL completed)
     {
         if (completed)
         {
             //completed move up..now move down
             [UIView animateWithDuration:0.5
                              animations:^
              {
                  Person.center = CGPointMake(Person.center.x, Person.center.y -100);
              }

              ];
         }
     }];

【问题讨论】:

  • 我添加了答案,请检查....

标签: ios objective-c xcode uiimageview


【解决方案1】:

试试这个代码...

-(void)repeatForever
{
[UIView animateWithDuration:0.5
                 animations:^

 {
     //move up
     Person.center = CGPointMake(Person.center.x, Person.center.y +100);

 }
                 completion:^(BOOL completed)
 {
     if (completed)
     {
         //completed move up..now move down
         [UIView animateWithDuration:0.5 animations:^{

             Person.center = CGPointMake(Person.center.x, Person.center.y -100);

         } completion:^(BOOL finished) {
             [self repeatForever];
         }];
     }
 }];

}

【讨论】:

  • 还有一个问题:当我离开应用程序并重新进入它时,动画停止并且我的图像就在那里。如何更改此设置,以便动画自动重启?
  • 重新进入app.add断点并检查时是否仍然调用此方法....
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-07
  • 2015-02-22
  • 2018-10-30
  • 1970-01-01
  • 1970-01-01
  • 2019-01-29
  • 1970-01-01
相关资源
最近更新 更多