2012-01-30 12 views
5

アニメーションを使用してナビゲーションバーを非表示にしてから、UIViewControllerを消すようにします。viewDidDisAppearでアニメーションが終了するのを待つ方法は?

-(void) viewWillDisappear:(BOOL) animated { 
    [UIView transitionWithView:self.view 
         duration:UINavigationControllerHideShowBarDuration 
         options:UIViewAnimationCurveEaseOut 
        animations:^{ 
     [self.navigationController setNavigationBarHidden:YES];  
    } 
        completion:^(BOOL finished){ 
        NSLog(@"animation finished"); 
    }]; 

    [super viewWillDisappear:animated]; 
} 

問題はviewWillDisappearを実行し、ちょうど戻って全体のビューは、アニメーションが終了する前に離れて行くし続けることである。したがって、私は次のように実装しています。アニメーションが完了する前にメソッドが戻るのを止めるにはどうしたらいいですか?

+0

アニメーションを作成することはできません。たぶんあなたは 'setNavigationBarHidden:animated:'メソッドを探していますか? –

+0

私は 'setNavigationBarHidden:animated:'を使いたくはありません。なぜなら、iOS 4(左にスライドする)とiOS 5(上にスライドする)で異なった動きをするからです。なぜなら、 'setNavigationBarHidden:animated:'を 'viewWillDisappear'ブロック内に置くことは、アニメーションが終了する前にメソッドが戻ることを意味するからです。私はおそらく2つのスレッドがここに必要と思いますか? –

答えて

2

viewWillDisappear:animatedは、本質的に礼儀の通知です。それが起こる前に差し迫っていることを伝えるだけです。ビューの消滅を実際にブロックしたり、遅らせることはできません。

あなたの最善の解決策は、(未テスト)などのメソッドを作成しますUINavigationControllerにカテゴリを作成するには、次のようになります。

- (void)pushViewControllerAfterAnimation:(UIViewController *)viewController animated:(BOOL)animated { 
    [UIView transitionWithView:viewController.view 
         duration:UINavigationControllerHideShowBarDuration 
         options:UIViewAnimationCurveEaseOut 
        animations:^{ 
         [self.navigationController setNavigationBarHidden:NO];  
        } 
        completion:^(BOOL finished){ 
         NSLog(@"animation finished"); 
         [self pushViewController:viewController animated:animated]; 
        }]; 
} 

- (void)popViewControllerAfterAnimationAnimated:(BOOL)animated { 
    [UIView transitionWithView:self.visibleViewController.view 
         duration:UINavigationControllerHideShowBarDuration 
         options:UIViewAnimationCurveEaseOut 
        animations:^{ 
         [self.navigationController setNavigationBarHidden:YES];  
        } 
        completion:^(BOOL finished){ 
         NSLog(@"animation finished"); 
         [self popViewControllerAnimated:animated]; 
        }]; 
} 

あなたはその後、代わりに

- (void)pushViewControllerAfterAnimation:(UIViewController *)viewController animated:(BOOL)animated

にこれらを呼び出すことができます

- (void)popViewControllerAfterAnimationAnimated:(BOOL)animated

である。

+0

素晴らしいと思う:)、私はあなたがtransitionWithViewを使用するときに何が起こるかわからないけれども:curveEaseInOutオプションで、そのように試したことはありません。 –

+0

私は同意する、私は完全にどちらか確信していない。 transitionWithViewの使用:OPのオリジナルコードから来ますが、私はそれをテストしていません。 –

関連する問題