Reputation: 2832
I am developing an iPhone app in which I have to show some customize picker in case of a button event. But I don't want to hard coded values for the frame of my custom pickerView. I searched and found keyboardWillShow
notification userInfo method, but in my case I am not showing keyboard so can't get frame out of it. Can anybody help me way out for getting keyboard frame that I can use for my customize picker?
Upvotes: 5
Views: 3115
Reputation: 161
You can use a UITextField
and call becomeFirstResponder
and immediately resignFirstResponder
on it, so it will be shown and hidden without actually seeing the keyboard.
the action method of the button will look like the following:
@IBAction func showPickerView(sender: AnyObject)
{
let textField = UITextField()
view.addSubview(textField)
textField.becomeFirstResponder()
textField.resignFirstResponder()
textField.removeFromSuperview()
}
And you could listen to the notification and get the height.
for further information: Get height of iOS keyboard without UIKeyboardWillShowNotification
Upvotes: 3