2012-06-05 15 views
24

कुंजीपटल छुपाए जाने पर कुंजीपटल दिखाए जाने के बाद मुझे नियंत्रित करने की आवश्यकता होती है, बटन दबाया जाता है। आईओएस पर कीबोर्ड छुपाते समय कौन सी घटना ट्रिगर होती है? धन्यवादआईओएस घटना जब कीबोर्ड छुपाता है

+0

http://developer.apple.com/library/ios/search /? q = कीबोर्ड + छुपाएं –

+0

संभावित डुप्लिकेट [आईपैड कीबोर्ड को कैसे छिपाया गया है] [http://stackoverflow.com/questions/7912246/ipad-how-to-now-keyboard-has-been-hidden) –

उत्तर

56

हाँ उपयोग निम्नलिखित

//UIKeyboardDidHideNotification when keyboard is fully hidden 
//name:UIKeyboardWillHideNotification when keyboard is going to be hidden 

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onKeyboardHide:) name:UIKeyboardWillHideNotification object:nil]; 

और onKeyboardHide

-(void)onKeyboardHide:(NSNotification *)notification 
{ 
    //keyboard will hide 
} 
+1

यह बर्खास्तगी के पल में ट्रिगर होगा, जब कुंजीपटल पूरी तरह छिपा हुआ न हो। –

+2

हां, सही, कृपया पूरी तरह से छुपा अधिसूचना उपयोग 'UIKeyboardDidHideNotification' के लिए अद्यतन उत्तर की जांच करें –

5

आप UIKeyboardWillHideNotification के लिए सुन सकते हैं, यह तब भी भेजा जाता है जब कीबोर्ड को खारिज कर दिया जाता है।

+7

सटीक होने के लिए, कुंजीपटल खारिज होने से पहले अधिसूचना भेजी जाती है। –

+0

@ हेनरी, सही ... क्योंकि मैं अभी इस से निपट रहा हूं। – Morkrom

3

आप को पता है जब उपयोगकर्ता प्रेस ठीक है बटन, आप UITextFieldDelegate प्रोटोकॉल को अपनाना चाहते हैं, तो आप देखें तो नियंत्रक इस विधि को लागू करता है:

स्विफ्ट 3:

func textFieldShouldReturn(_ textField: UITextField) -> Bool { 
    // this will hide the keyboard 
    textField.resignFirstResponder() 
    return true 
} 

आप बस जानना चाहते हैं जब कुंजीपटल दिखाया गया है या छिपा है, का प्रयोग कर एक Notification:

स्विफ्ट 3:

NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillShow(_:)), name: .UIKeyboardWillShow , object: nil) 

NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillHide(_:)), name: .UIKeyboardWillHide , object: nil) 

func keyboardWillShow(_ notification: NSNotification) { 
    print("keyboard will show!") 

    // To obtain the size of the keyboard: 
    let keyboardSize:CGSize = (notification.userInfo![UIKeyboardFrameBeginUserInfoKey] as! NSValue).cgRectValue.size 

} 

func keyboardWillHide(_ notification: NSNotification) { 
    print("Keyboard will hide!") 
} 
संबंधित मुद्दे