2011-12-22 10 views
0

2つのビュー(redView、blueView)を含むView Controllerが1つあります。ビューはメインビューよりも小さくなっています。UIViewcontroller.viewアニメーションとサブビューの切り替え

アニメーションでredViewからblueViewに変更したいと思います。これを使用しない場合、アニメーションは発生しません。私はこれにコードを変更する場合には

[UIView beginAnimations:@"View Flip" context:nil]; 
[UIView setAnimationDuration:1.25]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight 
         forView:redView cache:YES]; // !!! I WILL CHANGE THIS 

[self.view addSubview:blueView]; 
[redView removeFromSuperview]; 

[UIView commitAnimations]; 

、その後、アニメーションはOKですが、全体MAINVIEWは、私が起こることをしたくない何かをアニメーション化します。サブビューだけを反転させたい2つのサブビューが同じ位置にあることに注意してください。 (フレーム)どんなアイデアですか?あなたの最初の例で

[UIView beginAnimations:@"View Flip" context:nil]; 
[UIView setAnimationDuration:1.25]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight 
         forView:self.view cache:YES]; 

[self.view addSubview:blueView]; 
[redView removeFromSuperview]; 

[UIView commitAnimations]; 

答えて

0

ソリューションを見ているあなたのcontainerView redView、 に追加します。 tempViewにview1とview2を追加します。

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:1.0]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:tempView cache:YES]; 
[tempView addSubview:view2]; 
[view1 removeFromSuperview]; 
[UIView commitAnimations]; 

エクストラ:より良いアニメーションのためには、view1.visible = YES、NOの代わりにaddSubview、removeFromSuperViewを使用することができますが、彼らはすべての時間をあなたの助けのため

0

それはアニメーションの後にそれを削除してみてください、アニメーション化することができます前に、あなたがredViewを削除しているように見えます。

コード:

[UIView setAnimationDidStopSelector:@selector(removeRedViewFromSuperview)]; 
+0

感謝を割り当てられますが、それは動作しませんでした。私は解決策を見つけました。 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1.0]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:tempView キャッシュ:はい]; [tempView addSubview:view2]; [view1 removeFromSuperview]; [UIView commitAnimations]; –

+0

私の評判のためにまだ投稿できません –

4
単純なアニメーションについてアップルからの代わりに、単純なアニメーションの

使用ブロックのアニメーション、「このセクションの方法の使用は、iOS 4に落胆し、後には」

アニメーションブロックの

付き
[UIView transitionWithView:containerView 
        duration:1.25 
        options:UIViewAnimationOptionTransitionFlipFromRight 
       animations:^ 
{ 

        [redView removeFromSuperview]; 
        [containerView addSubview:blueView]; 

       } 
       completion:NULL]; 

containerView:アニメーションされるメインビューです。私はアニメーションを行ういるtempViewを使用

: はまた、より多くの情報のため、すべての:) が見つかり

http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html

関連する問題