1

I made textview and imageview and label inside scrollview, and I add textView.isScrollEnabled = false to scroll both. My Question is, When I click enter in the textview at the last line, My textview gets bigger but not scrolls to bottom! The cursor cuts off!

like this...

bug

but I want this...

enter image description here

Similar as this GIF.

enter image description here

My code

noteTextView.isScrollEnabled = false

photoImageView.translatesAutoresizingMaskIntoConstraints = false
noteTextView.translatesAutoresizingMaskIntoConstraints = false
bScrollView.translatesAutoresizingMaskIntoConstraints = false
dateLabel.translatesAutoresizingMaskIntoConstraints = false
nView.translatesAutoresizingMaskIntoConstraints = false

view.addSubview(bScrollView)
view.sendSubview(toBack: bScrollView)
bScrollView.addSubview(nView)
nView.addSubview(photoImageView)
nView.addSubview(dateLabel)
nView.addSubview(noteTextView)

bScrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
bScrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
bScrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
bScrollView.topAnchor.constraint(equalTo: topView.bottomAnchor).isActive = true

nView.leadingAnchor.constraint(equalTo: bScrollView.leadingAnchor).isActive = true
nView.trailingAnchor.constraint(equalTo: bScrollView.trailingAnchor).isActive = true
nView.bottomAnchor.constraint(equalTo: bScrollView.bottomAnchor).isActive = true
nView.topAnchor.constraint(equalTo: bScrollView.topAnchor).isActive = true
nView.widthAnchor.constraint(equalTo: bScrollView.widthAnchor).isActive = true

noteTextView.leadingAnchor.constraint(equalTo: nView.leadingAnchor, constant: 18).isActive = true
noteTextView.trailingAnchor.constraint(equalTo: nView.trailingAnchor, constant: -18).isActive = true
noteTextView.bottomAnchor.constraint(equalTo: nView.bottomAnchor).isActive = true
noteTextView.topAnchor.constraint(equalTo: dateLabel.bottomAnchor).isActive = true
noteTextView.heightAnchor.constraint(greaterThanOrEqualToConstant: 0).isActive = true

photoImageView.leadingAnchor.constraint(equalTo: nView.leadingAnchor).isActive = true
photoImageView.trailingAnchor.constraint(equalTo: nView.trailingAnchor).isActive = true
photoImageView.topAnchor.constraint(equalTo: nView.topAnchor).isActive = true
photoImageView.heightAnchor.constraint(equalToConstant: 300).isActive = true

dateLabel.leadingAnchor.constraint(equalTo: nView.leadingAnchor, constant: 12).isActive = true
dateLabel.trailingAnchor.constraint(equalTo: nView.trailingAnchor, constant: -12).isActive = true
dateLabel.topAnchor.constraint(equalTo: photoImageView.bottomAnchor).isActive = true
dateLabel.heightAnchor.constraint(equalToConstant: 30).isActive = true
14
  • Why you have set this textView.isScrollEnabled = false? Change it too true. Commented Dec 13, 2016 at 6:43
  • @User511 Because when I set 'isScrollEnabled = true' the whole textview disappears Commented Dec 13, 2016 at 6:45
  • @User511 And it has to be in UIScrollView! Commented Dec 13, 2016 at 6:48
  • First of all why you are adding text view in scroll view. Do you want to add something else in scroll view? Commented Dec 13, 2016 at 6:50
  • Please follow the steps in this answer: stackoverflow.com/questions/27652334/… Commented Dec 13, 2016 at 6:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.