2009-07-19 15 views
1

ナビゲーションバーを通常よりもゆっくりと表示したいと思います。アニメーションの長さを変更する

(以下ビューが正しくアニメーションん)私は、次を試してみましたが、隠れたときに、それが代わりに出てアニメーションを瞬時に消える:

[UIView beginAnimations:@"hideNavBar" context:nil]; 
[UIView setAnimationDuration:2.0]; 
[self.navigationController setNavigationBarHidden:value]; 
[UIView commitAnimations]; 

I代用した場合:

[self.navigationController setNavigationBarHidden:value animated:YES]; 

そして、それを私の遅いバージョンの代わりに通常の継続時間を使用します。うーん。

私も本当に狡猾取得しようと実行します。

CGFloat *durationRef = &UINavigationControllerHideShowBarDuration; 
CGFloat oldDuration = *durationRef; 
*durationRef = 2.0; 
[self.navigationController setNavigationBarHidden:value animated:YES]; 
*durationRef = oldDuration; 

_ _ BAD EXEに割り当てでアクセスをもたらしました。何か案は?

答えて

2

期間を変更したい場合は、独自に実装する必要があります。 UINavigationBarはビューです。実際のビューがなくてもレイヤーを取得して移動できます。基本的には、次のようなことをします:

//This routine starts animating the layer of the navigation bar off screen 
- (void)hideNavigationBar { 
    CALayer *layer = self.navigationBar.layer; 

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"]; 
    animation.duration = 4.0; 
    animation.toValue = [NSNumber numberWithFloatValue:(layer.position.y - self.navigationBar.frame.size.height)]; 
    animation.delegate = self; 
    [touchedLayer addAnimation:animation forKey:@"slowHide"]; 
} 

//This is called when the animation completes. We have not yet actally 
//hidden the bar, so on redraw it will snap back into blace. We hide it 
//here before the redraw happens. 
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL) finished { 
    if (finished) { 
    [self.navigationController setNavigationBarHidden:YES animated:NO]; 
    } 
} 

バーをアニメーション化するのは類似しています。これは、バーの動きに合わせて画面上の他のビューを拡大/縮小しないことに注意してください。調整する必要があるビューがあれば、別のアニメーションを設定する必要があります。

スピードを変更する作業は大変ですが、UIKitはそれを実行するように設定されていないため、Appleの組み込みのアニメーションで作業するのは地雷を歩くようなものです。あなたが本当に魅力的な理由を持っていない限り、私はあなたが正しく行動するすべてのものが価値あるものであるということを見つけることができると思います。

+0

を使用することができます。しかし、答えをありがとう。 –

+1

私はこれがうまくいくとは思わない。 –

+0

それはなぜでしょうか?あなたは常に画面上のレイヤーをつかんで、アニメーションを貼り付けることができます。参考までに、実験中にこれを行ったことがありますが、これを行う生産コードは出荷されていません。 –

0

あなたはまだ私はUINavControllerをreimplemebtingは優雅で小さなゲイン価値がないと判断しました最終的には

[UIView beginAnimations:@"FadeOutNav" context:NULL]; 
[UIView setAnimationDuration:2.0]; 
self.navigationController.navigationBar.alpha=0.0; 
[UIView commitAnimations]; 
関連する問題