【Xcode】UIViewのアニメーション
◼︎変更可能なプロバティの値
UIImageViewをアニメーションさせる時に、変化させることができるプロパティは以下の6種類です。
プロパティ | 意味 |
---|---|
frame | 座標とサイズ |
bounds | 座標とサイズ |
center | 中心座標 |
transform | 移動、拡大縮小、回転 |
backgroundcolor | 背景色 |
contentStretch | ストレッチ方法 |
alpha | 透明度 |
◼︎アニメーションの開始
// 任意ののオプション UIViewAnimationOptions myOption = UIViewAnimationOptionCurveLinear //等速 | UIViewAnimationOptionRepeat ; //繰り返し [UIView animateWithDuration:1.0 // アニメーションの秒数 delay:1.0 // 開始までの秒数 options:myOption animations:^{ sampleImage.center = CGPointMake(100, 100); //プロパティの設定 } completion:nil];//アニメーション終了時に行う処理(必要ないならnilに設定)
ここではオプションを等速と繰返しに設定しています。
複数設定したい場合は上記のように|で区切って指定してください。
代表的なオプションは以下の通りです。
オプション | 意味 |
---|---|
UIViewAnimationOptionRepeat | 繰り返し |
UIViewAnimationOptionCurveEaseInOut | 加速して開始、減速して終了 |
UIViewAnimationOptionCurveEaseIn | 加速して開始 |
UIViewAnimationOptionCurveEaseOut | 減速して終了 |
UIViewAnimationOptionCurveLinear | 等速 |
UIViewAnimationOptionBeginFromCurrentState | 現在の状態から開始する |
UIViewAnimationOptionAutoreverse | 再生が終了した後に逆再生する |
UIViewAnimationOptionAllowAnimatedContent | アニメーション中にアニメーションを許可 |
UIViewAnimationOptionAllowUserInteraction | 中断を許可 |