Cursor disappears under keyboard in UITextView - ios

When entering text into a UITextView, if you type enough lines or hit return enough times, the cursor will naturally go under the keyboard. Certain apps, such as the Apple Notes app, handle this just fine, scrolling the textview until the cursor is visible again. I have struggled to replicate this behavior. I've had no luck with textView.scrollRangeToVisible() with the selectedRange or textView.scrollRectToVisible() with the caret rect.
Some other things I've tried:
http://inessential.com/2014/01/07/uitextview_scroll-to-typing_bug
https://gist.github.com/DanielTomlinson/802b54f04dc0c4afe56a

I would try the following steps:
Make the UITextView's fill the entire height of the screen
Get the Keyboard Height Dynamically(See: Get the frame of the keyboard dynamically) This is especially important with the release of third party keyboards in iOS 8.
Then when the cursor goes below the keyboard, move the UITextView up by the screen height minus the keyboard height.

Related

UITextView on Catalyst with Long text, invisible text ranges when scrolling

I have an issue with Catalyst. I'm trying to display a long text in a UITextView, and on iOS everything works well, no issues.
On Mac (with Catalyst) however, when I scroll the textview, some parts disappear. Does anyone have an idea on how to fix this?
I have tried calling setNeedsLayout/Display/layoutIfNeeded on the textview when scrolling but no luck. The only thing that "worked" is to remove the textview from the view hierarchy and readd it to the container view on scroll finished. Still not ideal, as you lose selection when you want to select some text and scroll. (When I save the selection and re-apply it, then the blue highlight is invisible)
Using a UILabel in a scrollview could work, but then you lose all user interactions (no editing/selecting text)
Does anyone have any idea on how to fix this? Or I should just wait for Apple to fix this.
See the video/gif of the original issue:

How to prevent UITextView text moving to top on typing?

I want to prevent UITextView moving my text to top when I start a new line. In my app I expand/increase my UITextView height constraint size, so it has an enough space to continue showing text without moving the text to top and scroller appearing.
How can I prevent it? Can I turn off this feature? So when I'll add a new line to my textView it will not move my text to top and show me scroller? Because I have a space there.
Disable the scrolling in UITextView i.e. un-check scrolling.

The text in TextField going up and down when typing TexField

I have an issue, the text in my textfield is going up and down when I switch app go to other app and come back, loop this action 2-3 times, typing in textfield, and it show issue as same image below. I have check frame, size, it not move.
If the textview's height is dynamic, set scrollEnabled to false. If not, try increasing its frame height.

How to get rid of space between UITextField and Keyboard

I was wondering if anyone has seen a similar problem to this where you have a random blank space between the keyboard and a UITextField? For some reason I can't find anything about this and the end of the screen is the bottom of the UITextField. Any help would be greatly appreciated.
Example Screenshot showing space between keyboard and UITextField
Start by putting the text field in a UIScrollView.
Register your view controller to respond to the notification UIKeyboardDidShowNotification. This notification will give you a dictionary that has the size of the keyboard.
Once you have the size value, you will have to do some math to figure out what you want the scroll view's contentInset to be such that the text field is just above it.
Here's an example for getting the size of the keyboard: How to get UIKeyboard size with Apple iPhone SDK

how do I get the keyboard height prior to it needing to be shown

I'm structuring a view around the height of the keyboard. I don't want to have to wait asynchronously for my textfield to begin editing and scraping the keyboard NSNotification and then resizing my view.
Is it possible to ask the system for its keyboard height prior to it appearing?
Thankyou!

Resources