I am using swift 2.2 for an iOS application.
I have a UIButton with a .TouchUpInside event that fires a UITextField to become the first responder.
The following is the input:
self.manualInput = BrandTextField(y: 0, parentWidth: self.view.frame.width)
self.manualInput.returnKeyType = .Search
self.manualInput.autocorrectionType = .No
self.manualInput.hidden = true
self.manualInput.text = ""
self.manualInput.delegate = self
self.manualInput.autocapitalizationType = .AllCharacters
self.manualInput.moveX(0)
self.manualInput.changeWidth(self.view.frame.width)
self.manualInput.layer.cornerRadius = 0
self.backgroundView.addSubview(self.manualInput)
Below is the button:
self.keyboardButton = ActionButton(x: Dimensions.xScaleValue(170), y: Dimensions.yScaleValue(495), onTitle: "Enter code", offTitle: "Enter code", onImage: "manual_entry", offImage: "manual_entry", imageOn: true, action: {
self.manualInput.becomeFirstResponder()
print("Open the input")
})
self.backgroundView.addSubview(self.keyboardButton)
I also have these two observers:
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.keyBoardWillShow), name: UIKeyboardDidShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.keyBoardWillHide), name: UIKeyboardWillHideNotification, object: nil)
func keyBoardWillShow(notification: NSNotification) {
print("Keyboard will show")
let frame = (notification.userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
self.manualInput.moveY(frame.origin.y - self.manualInput.frame.height)
self.manualInput.hidden = false
}
func keyBoardWillHide(notification: NSNotification) {
print("Keyboard will hide")
self.manualInput.moveY(0)
self.manualInput.hidden = true
}
The problem is that when I press the button, as on iOS 11, the line getFirstResponder () gets in, but the keyboard does not appear.
The strange thing for me here is that if I initialize the input inside the view and do not hide that the button still does not work. If I don’t click on the input, close the keyboard, and THEN use the button to start.
I don’t know if I missed something in configuring this for iOS 11, or if I just can’t do this anymore?
Any help is widely appreciated.