@@ -185,6 +185,7 @@ class ResizeDemoViewController: UIViewController {
185185 private var maxHeight : CGFloat = 200
186186 private var startY : CGFloat = 0
187187 private var startHeight : CGFloat = 0
188+ private var textViewHeightConstraint : NSLayoutConstraint !
188189
189190 override func viewDidLoad( ) {
190191 super. viewDidLoad ( )
@@ -210,11 +211,13 @@ class ResizeDemoViewController: UIViewController {
210211 let panGesture = UIPanGestureRecognizer ( target: self , action: #selector( handlePan ( _: ) ) )
211212 resizeHandle. addGestureRecognizer ( panGesture)
212213
214+ textViewHeightConstraint = textView. heightAnchor. constraint ( equalToConstant: 100 )
215+
213216 NSLayoutConstraint . activate ( [
214217 textView. topAnchor. constraint ( equalTo: view. safeAreaLayoutGuide. topAnchor, constant: 20 ) ,
215218 textView. leadingAnchor. constraint ( equalTo: view. leadingAnchor, constant: 16 ) ,
216219 textView. trailingAnchor. constraint ( equalTo: view. trailingAnchor, constant: - 16 ) ,
217- textView . heightAnchor . constraint ( equalToConstant : 100 ) ,
220+ textViewHeightConstraint ,
218221
219222 resizeHandle. centerXAnchor. constraint ( equalTo: textView. centerXAnchor) ,
220223 resizeHandle. topAnchor. constraint ( equalTo: textView. bottomAnchor, constant: 0 )
@@ -227,14 +230,14 @@ class ResizeDemoViewController: UIViewController {
227230 switch gesture. state {
228231 case . began:
229232 startY = gesture. location ( in: view) . y
230- startHeight = textView . frame . height
233+ startHeight = textViewHeightConstraint . constant
231234
232235 case . changed:
233236 let deltaY = gesture. location ( in: view) . y - startY
234237 var newHeight = startHeight + deltaY
235238 newHeight = max ( minHeight, min ( newHeight, maxHeight) )
236239
237- textView . heightAnchor . constraint ( equalToConstant : newHeight ) . isActive = true
240+ textViewHeightConstraint . constant = newHeight
238241 view. layoutIfNeeded ( )
239242
240243 case . ended, . cancelled:
0 commit comments