     }
     
     func keyboardWillHide(notification: NSNotification) {
+        
+        // In case the keyboard is hidden, don't continue.
+        // This happens when running in the simulator with the keyboard hidden
+        // or when running in an iPad with a hardware keyboard connected.
+        guard !CGRectIsEmpty(originalFrame) else  { return }
         
         guard let userInfo = notification.userInfo else { return }
         guard let duration = userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSTimeInterval,

        }
        
        let animationCurve = UIViewAnimationOptions(rawValue: animationCurveRaw)
        
        UIView.animateWithDuration(
            duration,

            keyboardFinalFrameValue = userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue else {
                return
        }
        
        guard let duration = userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSTimeInterval,
            animationCurveRaw = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? UInt else {
