2016-04-11 2 views
0

「画像」アニメーションをのmultiple imagesに与える方法を 'UIView'で教えてください。UIViewの異なる場所にある複数の画像にアニメーションを与える方法は?

1)私は3つの画像を持っていました。

2)私は生き生き3 different locationsでこれら3 Imagesを追加したいが、1枚の画像some durationanimatedlyずつを追加意味します?

どうすればこの問題を解決できますか?

+0

あなたは腹腔領域のために遅くするためにuiimageviewアニメーションを速く必要としますか? – Shreyank

+2

UIView animateWithDuration? –

+0

@Shreyank ....遅くなるのは遅くない...しかし、3つの異なる場所で1つずつ、3つの画像を1つずつ追加したい... 1つの画像を1つの場所に配置した後、その画像を配置した後、次の画像をアニメーションしてそのような次の場所に –

答えて

0

あなたは、第2の画像をアニメーション化するというように、コード

UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"-t%d",1]]]; 
[imgView setBackgroundColor:[UIColor redColor]]; 

UIImageView *imgView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"-t%d",2]]]; 
[imgView2 setBackgroundColor:[UIColor redColor]]; 

UIImageView *imgView3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"-t%d",2]]]; 
[imgView3 setBackgroundColor:[UIColor redColor]]; 

[self.view addSubview:imgView]; 
[self.view addSubview:imgView2]; 
[self.view addSubview:imgView3]; 

[UIView animateWithDuration:0.5 delay:1.0 options:UIViewAnimationOptionLayoutSubviews animations:^{ 

    [imgView setFrame:CGRectMake(0, 0, 150, 150)]; 


} completion:^(BOOL finished) { 

    [UIView animateWithDuration:0.5 delay:1.0 options:UIViewAnimationOptionLayoutSubviews animations:^{ 
     [imgView2 setFrame:CGRectMake(self.view.frame.size.width - 150, 0, 150, 150)]; 

    } completion:^(BOOL finished) { 

     [UIView animateWithDuration:0.5 delay:1.0 options:UIViewAnimationOptionLayoutSubviews animations:^{ 
      [imgView3 setFrame:CGRectMake(0, self.view.frame.size.height - 150, 150, 150)]; 

     } completion:^(BOOL finished) { 


     }]; 

    }]; 

}]; 

以下のようにそれに役立つだろう最初のイメージアニメーションの目的での使用済みブロックのための画像1

一つをアニメーションにしたいあなたの要件ごとにあなた:

+0

@PKT ....あなたのコードはうまくいきます –

0

3つのビュー_redView_greenViewと言うと_blueView別の場所に一方からそれらを移動させる方法以下のチェックアウトします。私はあなたが望むならば、あなたが特定することができるランダムな場所を使用しました。 Here you can have working example of itちょうどViewAnimationsTest作業空間のプロジェクトを選択して実行してください。

- (int) randomFloatingGenerator : (int) max{ 
    return arc4random() % max; 
} 

- (void) animate3Views { 
    [UIView animateWithDuration:2.0 
        animations:^{ 
         _redView.transform = CGAffineTransformMakeTranslation([self randomFloatingGenerator : 270], [self randomFloatingGenerator:480]); 
         _greenView.transform = CGAffineTransformMakeTranslation([self randomFloatingGenerator : 270], [self randomFloatingGenerator:480]); 
         _blueView.transform = CGAffineTransformMakeTranslation([self randomFloatingGenerator : 270], [self randomFloatingGenerator:480]); 

        } completion:^(BOOL finished) { 
         [self animate3Views];//if don;t want continuous translation remove this line 
        }]; 
} 
+0

ここでは、その実例を持つことができます、https://github.com/rptwsthi/DevelopmentSupportWorkspaceちょうどViewAnimationsTestプロジェクトを選択作業スペースと実行します。 – rptwsthi

+0

@rptwsthi ...その例では、使用する必要のあるものを教えてください。 –

0

おそらく最も簡単な方法は、遅延付きのアニメーションを3つ使用することです。 myViewsをアニメーション化するビューの配列である

for (NSInteger i = 0; i < 3; i++) { 
     UIView *view = myViews[i]; 
     CGRect frame = [self frameForViewAtIndex: i]; 
     NSTimeInterval duration = 0.5; 
     NSTimeInterval delay = i * 0.5; 

     [UIView animateWithDuration: duration delay: delay options: 0 animations: ^{ 
      view.frame = frame; 
     } completion: nil]; 
    } 

は、frameForViewAtIndex:ビューに対応するフレームを返すメソッドです。

+0

@roselovelyこのコードでは何かが明確ではありませんか? –

+0

....画像を追加する方法を教えてください。 –

関連する問題