2012-01-18 60 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 2012-01-18 12:21:03

+0

什麼不工作?選擇器不調用或酒吧不移動? – OdNairy 2012-01-18 12:28:28

+0

它沒有隱藏起來。 – Priya 2012-01-18 12:29:34

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中查看這些代碼嗎?viewwilldis會出現嗎? – Priya 2012-01-18 11:28:11

+0

都只是應用程序提供的動畫標識符。你可以設置任何字符串爲 – 2012-01-18 11:32:45

0

你可以有一個UINavigationBar沒有導航控制器:

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

UITapGestureRecognizerUIGestureRecognizer具體子類,尋找單個或多個龍頭:

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 2012-01-18 11:42:03

+0

@OnNairy,它是方法聲明還是動畫代碼? – 2012-01-18 11:46:12

+0

您將其更改爲正確的變體。另外,發件人將是 - UITapGestureRecognizer。你可以通過這個 – OdNairy 2012-01-18 11:47:57