2017-11-07 9 views
2

저녁,iOS Swift : 화면에서 제약 조건이 업데이트되지 않았습니다.

scrollview 제약 조건에 문제가 있습니다. 제약 일정이 업데이트되도록,

// when the keyboard is shown, move up some elements 
    @objc func keyboardWillShow(notification: NSNotification) { 
     if let keyboardSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue { 

      // Bring up the scrol lview 
      print(scrollViewBottomConstraint.constant) 
      self.scrollViewBottomConstraint.constant = keyboardSize.height 
      print(scrollViewBottomConstraint.constant) 
      self.view.updateConstraints() 
      self.view.updateConstraintsIfNeeded() 
      self.view.needsUpdateConstraints() 
      self.view.layoutIfNeeded() 

      // Bring up the next arrow with animation 
      self.nextButtonBottomConstraint.constant = keyboardSize.height + 8 
      UIView.animate(
       withDuration: 1.0, 
       delay: 0.0, 
       usingSpringWithDamping: 0.5, 
       initialSpringVelocity: 6.0, 
       options: [.allowUserInteraction, 
          .curveEaseInOut], 
       animations: { 
        self.view.layoutIfNeeded() 
      }, completion: nil) 
     } 
    } 

콘솔 인쇄 0 이상 253 :

이 내 코드입니다. 그러나 화면 I의 변화를 볼 수 있으며, I는이 로그를 가지고

[스냅 숏 적어도 한번 렌더링 afterScreenUpdates이 필요하지 않은 도면 (0x7fa041471bc0, UIInputSetHostView)를 스냅 숏 : YES.

+0

는 u는 문제가 해결 되었습니까 :

view.layoutIfNeeded() 

는이 시도

은 제거하려고? – alegelos

답변

0

이상한, 단지 제약 조건을 변경 한 후 view.layoutIfNeeded()가 작업을 수행해야합니다.

self.view.updateConstraints() 
self.view.updateConstraintsIfNeeded() 
self.view.needsUpdateConstraints() 

그냥 :

@objc func keyboardWillShow(notification: NSNotification) { 
    guard let keyboardSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else{ 
     return 
    } 

    scrollViewBottomConstraint.constant = keyboardSize.height 
    nextButtonBottomConstraint.constant = keyboardSize.height + 8 
    view.layoutIfNeeded() 
} 
+0

어떨까요? [Snapshotting] 적어도 한 번 렌더링되지 않은 뷰 (0x7fa041471bc0, UIInputSetHostView) 스냅 샷에는 afterScreenUpdates : YES가 필요합니다. –

+0

@ TheMiotz는 그 코드만으로도 여전히 효과가 있습니까? – alegelos