0

I need to create a UI where, as the user types, the cursor/typing area stays in the middle of the page and the newly typed text is pushed 'up and off' the top of the page.

I've tried to set the cursor position to the bottom of a text view which covers 0.6 of the superview but that doesn't work (presumably because it doesn't have any text?). This is a great answer for general cursor placement but my use case isn't catered for.

The code I used to try place the cursor at the end of the text view is :

func setCursorPosition() {
        let newPosition = textViewOutlet.endOfDocument
        textViewOutlet.selectedTextRange = textViewOutlet.textRange(from: newPosition, to: newPosition)
    }

This doesn't work because it is looking for filled in text but sometimes the text view would be empty and I'd still need to load it on the bottom line.

The effect I'm trying to create would look like this :

enter image description here

quite a complex problem I think - any ideas?

nc14
  • 539
  • 1
  • 8
  • 26

1 Answers1

0

For people who have this problem in future. I solved this by coming at it from a different angle. Rather than attempting to place the cursor half way down the page, I removed the height constraints and made the text view dynamically resize based on the content.

Then I adjusted the constraints (helped by this answer) to fix the space to the bottom safe area but didn't specify a height.

This way, the text view dynamically resizes but in an upwards direction. When it reaches the gradient I have placed over the frame it starts to fade out.

Perfect (I also disabled scrolling to make this work)

Top tip - if something seems really hard there might be a different way to approach the problem!

nc14
  • 539
  • 1
  • 8
  • 26