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
Cœur
  • 37,241
  • 25
  • 195
  • 267
Daniel
  • 521
  • 1
  • 7
  • 16
  • Why you have set this textView.isScrollEnabled = false? Change it too true. – User511 Dec 13 '16 at 06:43
  • @User511 Because when I set 'isScrollEnabled = true' the whole textview disappears – Daniel Dec 13 '16 at 06:45
  • @User511 And it has to be in UIScrollView! – Daniel Dec 13 '16 at 06:48
  • First of all why you are adding text view in scroll view. Do you want to add something else in scroll view? – User511 Dec 13 '16 at 06:50
  • Please follow the steps in this answer: http://stackoverflow.com/questions/27652334/uitextview-inside-uiscrollview-with-autolayout – User511 Dec 13 '16 at 06:52
  • @User511 I said that already... I want to put `UIImageView`,`UILabel` and `UITextView` both in `UIScrollView`. – Daniel Dec 13 '16 at 06:53
  • @User511 I did that already but has same problem... – Daniel Dec 13 '16 at 06:54
  • Add another heightanchor to your textView for smallerThanEqual to restrict the height while editing. Set noteTextView.isScrollEnabled to true while textview has focus. When complete, you can relayout your view to ensure the entire text is visible and set scrollEnabled to false again. – Carien van Zyl Dec 13 '16 at 07:14
  • @CarienvanZyl Thank you! but what about scrollview and textview both scrolling? – Daniel Dec 13 '16 at 07:23
  • I think that putting a scrollview (textview) inside another scrollview is not healthy, instead, add the imageview inside the textview, yes you can -somehow- do it. – Ahmad F Dec 13 '16 at 07:25
  • @AhmadF Can you give me some detail please? – Daniel Dec 13 '16 at 09:21
  • How the main view should looks like? could you add a mockup or something? – Ahmad F Dec 13 '16 at 09:25
  • @Daniel Look at https://www.raywenderlich.com/50151/text-kit-tutorial if you want to put the image inside the textview. Otherwise, I think you need to disable scrolling of scrollview while editing and enable scrolling of textview. As soon as textview loose focus, you need to enable scrolling on scrollview and disable scrolling on textview. – Carien van Zyl Dec 13 '16 at 10:35
  • Thanks for helping! I will try `UIBezierPath`! – Daniel Dec 13 '16 at 12:11

0 Answers0