2014-10-11 102 views
0

我有一個UIImageView,當視圖加載時會移動。 它會先+100以上,然後設置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); 
       } 

       ]; 
     } 
    }]; 
+0

我加入answare,請檢查.... – hmdeep 2014-10-11 11:53:40

回答

0

試試這個代碼...

-(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]; 
     }]; 
    } 
}]; 

}

+0

真的謝謝了! – Sam0711er 2014-10-11 11:54:34

+0

還有一個問題:當我離開應用程序並重新進入時,動畫停止,我的圖像就在那裏。我該如何改變這一點,以便動畫自動啓動呢? – Sam0711er 2014-10-12 12:58:01

+0

當您重新進入app.add斷點並檢查它時仍然調用此方法.... – hmdeep 2014-10-13 03:53:53