2013-04-28 94 views
0

我想動畫一個ImageView的X位置,並重置它,如果它達到某個X位置。例如,開始一個700並移動到左邊。如果它達到100,我想將它重置爲700.並且不斷地反覆這樣做。動畫ImageView X的位置和重置

很確定需要一個計時器,但不知道如何去做這件事,因爲這是我的第一個IOS應用程序。搜索谷歌出現了很多動畫的東西,但都是不同的,這導致了混亂。 :)

回答

0

使用此代碼

呼叫幀/中心[自我動畫: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]; 

       }]; 

      }]; 
     } 
    } 
+0

謝謝,我相信我可以與之合作。 – james 2013-04-28 19:56:42

+0

我想問一件事。無論如何取消動畫?就像用戶按下按鈕一樣?謝謝 – james 2013-04-28 19:59:38

+0

看到編輯答案.... – Imodeveloper 2013-04-28 20:05:25