UIViewAnimation(2) | 初心者がiPhoneアプリを作るブログ

初心者がiPhoneアプリを作るブログ

初心者がiPhoneアプリを作るブログです.
入門レベルですので開発初心者にも,できるだけ分かるように丁寧に説明していきます(多分).

では続きです.
このエントリでは,UIViewAnimatoinTransitionについて見ていきます.

UIViewAnimationTransitionを使うと,特殊なアニメーションができます.
例えば,モーダルビューのフリップアニメーションができます.

使う場面が少ないかもしれませんが,知っていて損はないので,コードを載せておきます.

- (void)viewDidLoad
{
    [super viewDidLoad];


    [self.animationView setFrame:self.view.bounds];
    // buttonを押したらアニメーションが開始するように設定する
    // 以下ボタンの設定
    [self.view setBackgroundColor:[UIColor redColor]];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button setFrame:CGRectMake(320 / 2 - 40, self.view.frame.size.height - 50, 80, 30)];
    [button setTitle:@"Animation" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonTouched:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

- (
void)buttonTouched:(UIButton *)button{
    [UIView beginAnimations:@"AnimatoinTest" context:(__bridge void *)([NSNumber numberWithBool:YES])];
    // 設定できるUIViewAnimationTransition4つある.
    // それぞれ試してみて欲しい
    // 今回はフリップアニメーションにする
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO];
    //[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:NO];
    //[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:NO];
    //[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:NO];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    [UIView setAnimationCurve:ANIMATIONCURVE];
    [UIView setAnimationDuration:ANIMATIONDURATION];
    [self.view addSubview:self.animationView];
    [UIView commitAnimations];
}




こうすることで,モーダルビューのようなアニメーションを実装することができます.
これは,一部のビューにフリップアニメーションを付けたい場合や,
複数のビューを同時にフリップアニメーションさせたい場合に役に立ちます.

そんな場面ないかw

以上です.

HOMEに戻る