How to prevent UITextView text moving to top on typing? - ios

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.

Related

UITextView places text lower than I want it to be

I got UITextView with some text. Text always appears not in the upper left corner of the text view but with a large indent from upper border like this:
textView with text
I set attribute "content mode" to "Top left" like this but it did not helped:
attribute setted to top left
Method [self.infoTextView scrollRangeToVisible:NSMakeRange(0, 0)]; didn't helped.
Method [self.infoTextView setContentOffset:CGPointZero animated:NO]; can do the job BUT it moves text only if it is already visible to user so it creates a mess in a UI (First user sees text at the bottom and then text instantly changes position).
How do i place a text in the top left corner of UITextView before it appears on screen? Will appreciate any help, thanks in advance!
BTW I am using Xcode version 8.2.1.
Solution: I added fresh new textView and it's content was exactly in the top left corner. I am sure that i did nothing with textView in my code and in storyboard file. I saw this bug in more than one of my projects but previous time adding fresh new textView did not solve the problem. This time - it helped. Thanks for your answers!

Cursor disappears under keyboard in UITextView

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.

How do I have padding at the bottom of my UITextView like in Mail.app so the text isn't scrunched?

In Mail.app, if I go to create a new message and type all the way so the text is at the last line of the UITextView there is still a decent amount of space between the last line of text and the keyboard if you scroll down. But you can't type here. It's just nice padding so you can read it without it being scrunched against the keyboard, and if you select the text, the selection handles don't extend under the keyboard.
My question is, how do I mimic this with a traditional UITextView?
I think you can do this by setting the contentInset property of your UITextView:
myTextView.contentInset = UIEdgeInsetsMake(-4,-8,0,0);
btw... the values above are not specific to your situation. You will want to adjust these to get the inset you are looking for.

UITextView won't scroll from outside particular area

I have a UITextView with approx 100 lines(for testing purpose its static) which scrolls fine but when i try to scroll from approx 150 its from the bottom i can not scroll. That means it lets me scroll from only certain area of the textview. for example see the image below. If i try to select and scroll above 3 line from top, i can scroll but below 3rd line, It won't let me scroll. I went through documentation but couldn't find anything that makes sense.
Try resizing the frame of your UITextView so it does not overlap the UITabBarView. If you create this in interface builder, you can resize it there.
if there is some area that is not taking ui touches, thAT means, your UITextView is being overlapped by another view. try:
[self.view bringSubviewToFront:textView];
also think about Enrico's answer.
Put Background color for TextView. It will give you extact idea of TextView Complete framing and is it sub view of background or foreground.

How to ensure that only a certain section of a UIScrollView appears to slide?

I use a UIScrollView that has horizontal sliding enabled.
The Heading of the scroll view is Instructions for Using this App
And below that, I have instructions, one instruction per "page".
When the user scrolls horizontally, new instructions show. However, during this horizontal scrolling, the "Instructions for Using this App" from the second page also appears to move.
Instructions for Using this App <--- I do not want this to appear to slide
1. Instruction number 1. XYZ...
more text more text more text
more text more text more text <--- I want only this to slide
How to achieve this?
You can place separate UIView (probably UILabel in your case) on top of your UIScrollView, so your UI hierarchy will be something like:
UIView (screen)
UILabel (header)
UIScrollView (scrolled content)

Resources