2012-01-18 14 views

答えて

0
UITapGestureRecognizer* tapGesture =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(your_selector)]; 
tapGesture.numberOfTapsRequired = 2; 
[self.view addGestureRecognizer:tapGesture]; 
[tapGesture release]; 

-(void)your_selector{ 
    [UIView animateWithDuration:0.5 
       animations:^{ 
        bar.frame = CGRectOffset(bar.frame, 0, bar.bounds.size.height*bar.frame.origin.y<0?-1:1); 
       }]; 
} 

あなたが唯一持っている。この実装では、二重バーのステータスを反転させるタッチイベントです。 残念ながら、一度にシングルタッチとダブルタッチジェスチャーの実装が容易ではありません。より多くの人間の行動とあなたのための簡単 - ダブルタッチのイベントでのみ動作します。

XCode project - example

+0

しかし、それは動作していません... – Priya

+0

何がうまくいかない?セレクタは呼び出されないか、移動されません。 – OdNairy

+0

それは隠れていません。 – Priya

0

[UIView beginAnimations:@"Hide bar animation" context:NULL]; 

[UIView setAnimationDuration:0.5]; 

navigationBar.alpha = 0.0; 

[UIView commitAnimations]; 

for showing 

[UIView beginAnimations:@"Show bar animation" context:NULL]; 

[UIView setAnimationDuration:0.5]; 

navigationBar.alpha = 1.0; 

[UIView commitAnimations]; 

を隠すためにこれをしようとしたがUINavigationControllerと、それはあまりにも簡単です...あなたのセレクタで

+0

バーのアニメーションを非表示にしてバーのナビゲーションを表示することはどういう意味ですか? viewwillappearとviewwilldisappearでこのコードを試しても大丈夫ですか? – Priya

+0

は両方とも、アニメーションのアプリケーション提供識別子です。あなたはそのための任意の文字列を設定することができます –

0

あなたはナビゲーションコントローラなしUINavigationBarを持つことができます。

navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 40.0f)]; 
[navBar setDelegate:self]; 
[mainView addSubview:navBar]; 

UITapGestureRecognizerは、単一または複数のタップを探しUIGestureRecognizerの具象サブクラスである:ここでは

UITapGestureRecognizer *doubleTap =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideNavBar:)]; 
[doubleTap setNumberOfTapsRequired:2]; 
[YOURVIEW addGestureRecognizer:doubleTap]; 

UITapGestureRecognizer *singleTap =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showNavBar:)]; 
[singleTap setNumberOfTapsRequired:1]; 
[YOURVIEW addGestureRecognizer:singleTap]; 

ですナビゲーションバーを表示または非表示にするメソッド:

- (void)hideNavBar:(id)sender 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:1.0f]; //Animation duration in seconds 

    navBar.alpha = 0.0f; 

    [UIView commitAnimations]; 
} 

- (void)showNavBar:(id)sender 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:1.0f]; //Animation duration in seconds 

    navBar.alpha = 1.0f; 

    [UIView commitAnimations]; 
} 
+0

セレクタ間違い - セレクタが間違っています – OdNairy

+0

@OdNairy、メソッド宣言またはアニメーションコードですか? –

+0

バリアントを修正するために変更しました。また、送信者は - UITapGestureRecognizerになります。あなたは 'id'をこれで置き換えることができます – OdNairy

関連する問題