Programming/iOS

[ios/Swift3.0] TextView re-positioning when keyboard shown

devssun 2017. 8. 25. 09:30
728x90
반응형

TextView re-positioning when keyboard shown

(Swift TextView resize when keyboard shown : Swift TextView 키보드 리사이즈)

  • control TextView in ScrollView

  • we need textViewDidBeginEditing(), textViewDidEndEditing() function (override)

  • when keyboard shown (become editing mode), we control scrollview's contentOffSet

  • change x, y coordinate

func textViewDidBeginEditing(_ textView: UITextView) {
    if memoTextView == textView{
      scrollView.setContentOffset(CGPoint(x: 0, y: 350), animated: true)
      }
}
func textViewDidEndEditing(_ textView: UITextView) {
    scrollView.setContentOffset(CGPoint(x: 0, y: 330), animated: true)
}


반응형