0

I have a very simple screen.

a UITextView and UITextField.

basically, what I want to achieve is that when a user types something into the UITextField, it goes into the UITextView.

Obviously the UITextView has userInteractionEnabled : NO and it won't never show the keyboard. To make it nicer I also wanted the cursor to be always shown (kinda matrix talking to you :-). To achieve this i placed a little subview into the UITextView with a width of 2 and a height of 20 (enough for my font size) and the following piece of code into the viewDidLoad:

    UIView.animate(withDuration: 1, delay: 0, options: .repeat, animations: {() -> Void in
        self.cursorView.alpha = 0 }, completion: {(animated: Bool) -> Void in
            self.cursorView.alpha = 1
    })

Now, the question is: how can I dynamically move the cursorView according to the text that will be written (automaGically) into the UITextView?

Is there a way to recognise its length - position or anything else?

nynohu
  • 1,628
  • 12
  • 12
Alex
  • 271
  • 2
  • 4
  • 18
  • why not just use a ▌symbol at the end? – koropok Dec 27 '16 at 01:09
  • 'cause it's not blinking :-) – Alex Dec 27 '16 at 01:13
  • I think [this](http://stackoverflow.com/a/11487125/4539192) answer may help you. You can find out the space or x,y occupied by a word at a particular position in a `UITextView` and use it to animatedly move your cursor! – Rikh Dec 27 '16 at 04:44

0 Answers0