2016-08-01 15 views
1

Ich habe die zwei UIKeyboardNotifications (keyboardWillShow und keyboardWillHide) registriert und beide werden ausgelöst. Das Problem tritt auf, wenn die Animation für das Textfeld, das an die ursprüngliche Position zurückbewegt werden soll, erst nach dem Verschwinden der Tastatur ausgelöst wird. Gibt es überhaupt eine Verringerung der Verzögerung zwischen dem Abrufen der Benachrichtigung und dem Animieren des Textfelds?UIKeyboardWillHideNotification Verzögerung in der Animation

func keyboardWillShow(notification: NSNotification) { 
    let info = notification.userInfo! 
    let keyboardFrame : CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue() 
    duration = (info[UIKeyboardAnimationDurationUserInfoKey]?.doubleValue) 
    let rawAnimationCurve = (notification.userInfo![UIKeyboardAnimationCurveUserInfoKey] as! NSNumber).unsignedIntValue << 16 
    animationCurve = UIViewAnimationOptions(rawValue: UInt(rawAnimationCurve)) 
    let moveAmount = keyboardFrame.height 
    UIView.animateWithDuration(duration!, delay:0, options: animationCurve, animations: { 
     self.txtfield.transform = CGAffineTransformMakeTranslation(0.0, -self.moveAmount) 
     }, completion:nil) 
} 

func keyboardWillHide(notification: NSNotification) { 
     UIView.animateWithDuration(duration, delay:0, options:animationCurve, animations: { 
      self. txtfield.transform = CGAffineTransformMakeTranslation(0.0, 0.0) 
      }, completion:nil) 
} 

GIF image here

Antwort

1

ein Problem Realisiert, es war ein Flüchtigkeitsfehler von mir.

Hinzugefügt:

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(viewController.keyboardDidHide), name: UIKeyboardWillHideNotification, object: nil) 

statt:

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(viewController.keyboardWillHide), name: UIKeyboardWillHideNotification, object: nil)