在我的應用程序中激活屏幕鍵盤時,隱藏iOS導航欄。我怎樣才能防止這種情況發生?當用戶在搜索欄中,並且用戶點擊它時,就會發生這種情況。iOS在屏幕鍵盤出現時隱藏導航欄
一旦用戶點擊取消或搜索/完成編輯,我設法在搜索頁面上顯示導航欄,但搜索欄隨後進入導航欄。
我沒有在界面生成器上選擇「隱藏欄,如果鍵盤出現」。
在我的應用程序中激活屏幕鍵盤時,隱藏iOS導航欄。我怎樣才能防止這種情況發生?當用戶在搜索欄中,並且用戶點擊它時,就會發生這種情況。iOS在屏幕鍵盤出現時隱藏導航欄
一旦用戶點擊取消或搜索/完成編輯,我設法在搜索頁面上顯示導航欄,但搜索欄隨後進入導航欄。
我沒有在界面生成器上選擇「隱藏欄,如果鍵盤出現」。
試試這個,
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShowNotification:", name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHideNotification:", name: UIKeyboardWillHideNotification, object: nil)
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)
}
func keyboardWillShowNotification(notification: NSNotification) {
self.navigationController?.navigationBarHidden = false
}
func keyboardWillHideNotification(notification: NSNotification) {
self.navigationController?.navigationBarHidden = false
}
> NSDictionary* info = [note userInfo];
> CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
> UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height+80, 0.0);
> _scrollBackground.contentInset = contentInsets;
> _scrollBackground.scrollIndicatorInsets = contentInsets;
只取一個布爾值,當鍵盤出現時將其真實的,並呼籲prefersStatusBarHidden並返回YES,當鍵盤消失返回NO來prefersStatusBar Hideen –
不得不在導航欄或tableview中採取搜索控制器?你能上傳你的搜索欄的編碼部分嗎?或者按照這個鏈接。我在我的項目中包含了搜索欄,並且它完美地工作。 http://stackoverflow.com/questions/30752638/ios-swift-how-to-make-a-floating-search-bar-with-drop-down-list-like-this-i/30753256#30753256 –
@Lizzeiy你找到了解決方案嗎? –