UIView アニメーション
UIViewのクラスメソッドを使ったAnimation処理についてです。
パターンとして,2つ存在しますが, いずれもUIViewのクラスメソッドのはずです。iOS4.0以降では, Blockを使ったanimateWithDurationをおすすめしているようですが…
1. beginAnimations, commitAnimations
setAnimationCurve
アニメーションの動きを指定できます。
[UIView setAnimationCurve:UIViewAnimationCurve.UIViewAnimationCurveEaseIn];
UIViewAnimationCurveというのが動作になります。
| UIViewAnimationCurve | Description |
|---|---|
| UIViewAnimationCurveEaseInOut | 加速して始まり減速して終わり |
| UIViewAnimationCurveEaseIn | 加速して始まる |
| UIViewAnimationCurveEaseOut | 減速して終わる |
| UIViewAnimationCurveLinear | 等速 |
サンプル
CGContextRef context = UIGraphicsGetCurrentContext(); [UIView beginAnimations:nil context:context]; [UIView setAnimationDuration:0.5]; [UIView setAnimationDelegate:self]; // Where is end deletegate [UIView setAnimationDidStopSelector:@selector(finishAnimation)]; [UIView setAnimationCurve:UIViewAnimationCurve.UIViewAnimationCurveEaseIn]; // Here is animation Operration CGAffineTransform t3 = CGAffineTransformScale(view.transform, 2.0, 0.5); view.transform = t3; [UIView commitAnimations];
- (void)finishAnimation
{
NSLog(@"Animation Done!");
}
setAnimationDidStopSelector では, 終了時のメソッドがしてできます。setAnimationDelegateでクラスの指定が必要です。
2. animateWithDuration:animations
ここでもいくつかの形があります。
[UIView animateWithDuration:5.0f
animations:^{
// Processing
}];
最初の引数はAnimationする時間です。 animationsブロックにアニメーションの処理を書きます。
[UIView animateWithDuration:0.1f
animations:^{
// Processing
}
completion:^(BOOL finished){
// After finishing
}];
アニメーションのオプションを追加した場合
UIView animateWithDuration:2.5f
delay:1.0f
options:UIViewAnimationOptionCurveEaseIn
animations:^{
// Processing
} completion:^(BOOL finished) {
// Finish
}];
オプションは, beginAnimationsの場合と同じです。
