2013-03-29 83 views
0

我的mapview應用程序,我有一個搜索欄用於搜索具體的地址。 它現在起作用,它以地圖上方的「靜態」方式出現。 我的想法是做它用一個按鈕「搜索」的出現和disapperar如圖片:xcode - 使搜索欄出現/消失

enter image description hereenter image description here

任何想法有關HOY做thath? 在此先感謝

+1

你有什麼嘗試嗎? 'searchBar.hidden = true;'? – woz

+0

謝謝woz,我只是嘗試你的提示。它的工作原理雖然我正在考慮動畫(從/到頂部)。 – doxsi

回答

1

您可以在代碼中執行此操作。你所要做的就是改變它的框架。

將其添加到您的navigationBar.frame及其下方,然後,當圖標被點擊時,將其放下。我通常使用這個代碼,使它看起來不錯過:

[UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ 
     //Move it down here by changing its .frame 
    }completion:^(BOOL finished){ 
    }]; 
1

你只需要改變的UISearchBar的框架,你點擊搜索圖標來顯示它。 請參閱

最初,當您不顯示UISearchBar時您應該以這種方式設置Frame。

最初設置UISearchBar框架的邊框視圖框架。

thisSearchBar.frame = CGRectMake(0.0, -50.0, searchBarWidth, searchBarHeight)];viewDidLoad方法

在點擊搜索圖標顯示的UISearchBar

- (void)showSearchBar{ 
[UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ 

    thisSearchBar.frame = CGRectMake(0.0, 50, searchBarWidth, searchBarHeight)]; 

    }completion:^(BOOL finished) 
    { 
    }]; 

}

和你完成工作,搜索欄再次呼籲設置搜索欄的幀動畫

- (void)hideSearchBar{ 
[UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ 

    thisSearchBar.frame = CGRectMake(0.0, -50, searchBarWidth, searchBarHeight)]; 

    }completion:^(BOOL finished) 
    { 
    }]; 

    } 
+0

對不起,我晚了(我在度假)。你的解決方案出現我lookinf,但什麼是「圖像」(在image.size.width中使用)? – doxsi

0

P呃我的評論,只需使用:

searchBar.hidden = true;