Link per la domanda precedente: UITextField text jumpsUITextField testo salti iOS 9
Brevemente: Ho ViewController
con 2 UITextField
elementi. Quando loginField è firstResponder, dopo
self.passwordField.becomeFirstResponder()
testo in campo di accesso salta alto a sinistra e viceversa. E per di più strano: questo glitch riproduce solo la prima volta, quindi è necessario ricreare ViewController
a osservare questo comportamento
Qui è il video del problema tecnico http://tinypic.com/player.php?v=6nsemw%3E&s=8#.VgVb3cuqpHx
ho finito con questo (non funziona per iOS 9) :
func textFieldShouldReturn(textField: UITextField) -> Bool {
if textField === self.loginField {
self.loginField.resignFirstResponder()
// Shitty workaround. Hi, Apple!
self.loginField.setNeedsLayout()
self.loginField.layoutIfNeeded()
self.passwordField.becomeFirstResponder()
return false
}
return true
}
C'è qualcuno che è stato stucked con questo errore? Eventuali suggerimenti?
notifiche della tastiera gestori
mio punto di vista principale è UIScrollView, per il quale a cambiare lo spazio in basso a Superview, così l'utente può scorrere tutti i contenuti anche quando la tastiera è mostrato
func keyboardWillShow(notification : NSNotification) {
let keyboardInfo = notification.userInfo!
let keyboardFrame = keyboardInfo[UIKeyboardFrameEndUserInfoKey]!.CGRectValue
let animDuration = keyboardInfo[UIKeyboardAnimationDurationUserInfoKey]!.doubleValue!
UIView.animateWithDuration(animDuration, animations: {
self.scrollViewBottom.constant = keyboardFrame.height
self.view.layoutIfNeeded()
let offsetY = CGRectGetMaxY(self.loginButton.frame) + 10 - self.scrollView.frame.height
if offsetY > 0 {
self.scrollView.contentOffset = CGPointMake(0, offsetY)
}
})
}
func keyboardWillHide(notification : NSNotification) {
self.scrollViewBottom.constant = 0
self.view.layoutIfNeeded()
}
Come ho scoperto le notifiche della tastiera in iOS7, 8 e 9 sono molto diversi. Quindi, in iOS 9 le notifiche vengono inviate mentre si modifica FirstResponder anche se la tastiera non mostra/nasconde. Inoltre, quando cambio FirstResponder toccando su textField (non toccando Next sulla tastiera che viene gestito dal mio codice), c'è solo la notifica KeyboardWillShow e nessun KeyboardWillHide. E per quanto riguarda me, userInfo ha alcuni valori telaio spazzatura, qui sta il login quando si cambia first responder tramite pulsante accanto (funziona bene, senza difetti):
2015-10-07 12: 54: 13.870 keyboardWillHide: [ UIKeyboardFrameBeginUserInfoKey: NSRect: {{0, 352}, {320, 216}}, UIKeyboardCenterBeginUserInfoKey: NSPoint: {160, 460}, UIKeyboardFrameEndUserInfoKey: NSRect: {{0, 568}, {320, 216}}, UIKeyboardCenterEndUserInfoKey : NSPoint: {160, 676}, UIKeyboardAnimationDurationUserInfoKey: 0.25, UIKeyboardIsLocalUserInfoKey: 1, UIKeyboardBoundsUserInfoKey: NSRect: {{0, 0}, {320, 216}}, UIKeyboardAnimationCurveUserInfoKey: 7] 2015/10/07 12: 54: 13,896 keyboardWillShow: [UIKeyboardFrameBeginUserInfoKey: NSRect: {{0, 352}, {320, 216}}, UIKeyboardCenterBeginUserInfoKey: NSPoint: {160, 460}, UIKeyboardFrameEndUserInfoKey: NSRect : {{0, 352}, {320, 216}}, UIKeyboardCenterEndUserInfoKey: NSPoint: {160, 460}, UIKeyboardAnimationDurationUserInfoKey: 0.25, UIKeyboardIsLocalUserInfoKey: 1, UIKeyboardBoundsUserInfoKey: NSRect: {{0, 0}, {320 , 216}}, UIKeyboardAnimationCurveUserInfoKey: 7]
E qui viene il login quando si tocca sul secondo textField:
2015-10-07 12:55:13.879 keyboardWillShow: [UIKeyboardFrameBeginUserInfoKey: NSRect: {{0, 352}, {320, 216}}, UIKeyboardCenterBeginUserInfoKey: NSPoint: {160, 460}, UIKeyboardFrameEndUserInfoKey: NSRect: {{0, 352}, {320, 216}}, UIKeyboardCenterEndUserInfoKey: NSPoint: {160, 460},
UIKeyboardAnimationDurationUserInfoKey: 0.25, UIKeyboardIsLocalUserInfoKey: 1, UIKeyboardBoundsUserInfoKey: NSRect: {{0, 0}, {320, 216}}, UIKeyboardAnimationCurveUserInfoKey: 7]
Risoluzione
Ho scoperto che ho un altro controller per tastiera che riceve le notifiche della tastiera e crea alcune animazioni. Ecco dove sta il problema
Come stai gestendo la tastiera? Hai delle notifiche registrate per la tastiera visualizzata/nascosta? Se sì, puoi pubblicare il codice che cosa fai lì? – haluzak
Tnx per l'aiuto, controlla il post modificato – user3237732
Si sta per nascondere la notifica perché si chiama resignFirstResponder() prima di diventareFirstResponder(), il "salto" è causato dall'animazione in keyboardWillShow() – haluzak