2016-08-17 26 views
1

行,所以我有出現,並用鍵盤隱藏(當鍵盤出現它也出現當我關閉鍵盤它也與鍵盤消失)正在進行的動畫引起延遲,同時移動到另一個視圖控制器

因此,當我」 A button中號按此button這將打開另一個瀏覽器的過渡不會立即開始有延遲的少量(這是不好的)

我的按鈕的動畫:

func keyboardWillShow(notification:NSNotification) { 
    let userInfo:NSDictionary = notification.userInfo! 
    let duration: Double = (notification.userInfo![UIKeyboardAnimationDurationUserInfoKey] as! Double) 
    let keyboardFrame:NSValue = userInfo.valueForKey(UIKeyboardFrameEndUserInfoKey) as! NSValue 
    let keyboardRectangle = keyboardFrame.CGRectValue() 
    self.nextButtonConstraint.constant = keyboardRectangle.height 
    UIView.animateWithDuration(duration) { 
     self.nextButton.layoutIfNeeded() 
    } 

} 

func keyboardWillHide(notification:NSNotification) { 
    let duration: Double = (notification.userInfo![UIKeyboardAnimationDurationUserInfoKey] as! Double) 
    self.nextButtonConstraint.constant = -50 
    UIView.animateWithDuration(duration) { 
      self.nextButton.layoutIfNeeded() 

    } 
} 

我累了禁用的動畫,同時按鈕被按下,但它並沒有奏效:根據本similar question

@IBAction func nextButtonAction(sender: AnyObject) { 

    UIView.setAnimationsEnabled(false) 
    performSegueWithIdentifier("nextToPasswordSegue", sender: self) 
    UIView.setAnimationsEnabled(true) 
} 

答案:

顯然有一個動畫在同一時間,這是怎麼回事造成問題。

任何線索我該如何解決這個問題?

回答

0

我遇到了同樣的問題,當我試圖移動到下一個控制器時出現延遲。對我來說,修復它的方法是在執行segue之前隱藏鍵盤(resignFirstResponder)。然後,您將需要在主隊列上運行您的執行隊列,以確保其立即觸發。這裏有一個例子:

textField.resignFirstResponder() 
dispatch_async(dispatch_get_main_queue()) { 
    performSegueWithIdentifier("nextToPasswordSegue", sender: self) 
} 
相關問題