iPhone Dev - I have some textviews inside a scrollview. Can I make it scroll up as I type into them (so I can always see what I'm typing)? - iphone

I have an app that has a scrollview with a bunch of different textviews in it (when you click on each one, a keyboard pops up and you can type into the textview). See the following pic:
Here's my problem. If I enter any more text than is entered there in the pic, it goes underneath the keyboard so you can't see what you're typing. Is there any way I can make it so that when you're typing and you get down to that last line the the pic, it will automatically continue to scroll up one line at a time so that it always shows what you're typing (with the most recent line right above the keyboard)?

The best thing to do is to resize the textview when it becomes the first responder and when it resigns as first responder.
Resize the textview to fit within visible area when the keyboard is showing
Resize the textview to it's original size when done is pressed.
Check out this post as well.
How to make a UITextField move up when keyboard is present?

Related

Swift: textView method "scrollRangeToVisible" not working after changing UI Text View size in storyboard?

I'm new to swift. When my UItextView is filled up, I would like to have my UItextView to automatically scroll to what I have typed (bottom of UItextView).
I used scrollRangeToVisible and it had worked for the first time. However, after I changed the UItextView UI Size to be smaller, it hasn't been working ever since.
This is the code I have now.
let range = NSMakeRange(textView.text.count - 1, 0)
textView.scrollRangeToVisible(range)
The behavior seems weird to me.
First, it will not automatically scroll to the bottom, then, after I manually scrolled it to the bottom and type letters to the UItextView, it will pop up a blank page like this:
Random blank pop up
.Then type letters again it will be scrolled to the bottom for once:
Scrolled to bottom
.Then type again it will have larger bank pop up:
Larger random blank pop up
.Type again the blank becomes even larger:
Blank pop up filled up
.Then type again the scroll down to bottom works for once again:
Scroll to bottom works again
. After keep typing, this will finally work, the UItextView will scroll to the very bottom when typing a new line.
It's been a very weird problem and I have seen some resources saying emoji will cause problem for "scrollRangeToVisible".
Thanks for the help!
You can try scrolling to where your caret is:
textView.scrollRangeToVisible(textView.selectedRange)

Keyboard accessory view hiding text

I have the following problem: I have a standard UITextView which I resize once the keyboard pops up. I also have another view which I animate into view (not the standard accessory view attached to the keyboard). The problem is that I do not want text to be hidden by this view. This is what happens when I reach the last line (orange view = my custom accessory view):
Ideally, I'd like to have an automatic scroll should that happen. But I have no clue how to achieve this if I am in the last line of the UITextView. Also, scrollToVisible doesn't work in this context and I don't know if I'd get anywhere with contentInset.
Any suggestions would be welcome! Thanks.
EDIT
I suppose I would need some kind of mechanism which would allow to
make the textview only expand to the line right above the accessory view if I was entering something on the LAST LINE
have the textview expand to the keyboard if I was not editing the LINE DIRECTLY ABOVE the KEYBOARD.
Does that make sense? What I need is the opposite of contentInset, I suppose.
I simply don't want to resize the textView to just above the accessory view as it takes away screen space to display text.
I got the solution- sorry, I guess it was obvious, but it took me the whole day to figure it out:
textOfPage.contentInset = UIEdgeInsetsMake(0, 0, 100, 0);
This will offset my UITextView so that the last line is never hidden. The 100 is in pixels and can be adjusted accordingly.
What I would do is resize the textview in the textViewShouldBeginEditing method to fit above the keyboard and the newly added accessory view, and then resize it back to full screen when the keyboard is dismissed in textViewShouldEndEditing

iPhone Keyboard Adjust In View

I've been searching, but haven't quite found a complete answer, and the Apple docs aren't much help.
I have an application with a UIView that has a lot of text fields on it, ranging from the top of the view to the bottom. When the user clicks the first UITextField the keyboard pops up. The keyboard has three buttons above it, previous, next, and done on a toolbar InputAccessoryView.
Basically, let's say there are 6 UITextField boxes that space from the top of the view to the bottom. When the user gets past the third text field, the keyboard blocks the bottom three. How do I have the view adjust up when putting text in the bottom three text fields?
You need to place your textfields into a UIScrollView, and either translate the view above the keyboard when it is active and away when it is down, or another solution such as always having the keyboard up on that page, which'll save you the setFrame calls on your UIView/UIScrollView depending on what the keyboard is doing.
This will further help:
How to adjust the view position when the keyboard opens in iPhone?

How do I get around my UITextField's HUGE auto-correct dismissal area?

In my UITableView, each row has a text field or switch as its accessory view (a bit like the Settings app). The textFields are set with Auto-capitalisation ON. But the auto-correct prompt (the one you tap to dismiss the suggestion) seems to react to finger presses up to 65 px below the actual textField!
This means, for example, if a user types something in a textField, and then tries to press a UISwitch in the row below (without pressing return), instead of pressing the switch, their first press dismisses the autocorrect. For the user this is both confusing (they have to tap the switch twice) and annoying (they dismiss the text field's correction without meaning to).
Is there any way around this without having gigantic table rows or disabling autocomplete?
Maybe you could have a timer of 1 or 2 seconds that check and resign the textfield automatically.

adding a textbox and a button at the top of the keyboard on iphone

I want to add a text box and a button beside it. They will be at the bottom of the window. Then, when I touch the textbox (to type something), keyboard will appear and the whole row (with textbox and button) scrolls up and the keyboard will be right below them. Could you please let me know how can I do that?
Is there any sample program?
Thanks.
Matt Gallagher posted this on his blog:
Sliding UITextFields around to avoid the keyboard
It is a step by step example of exactly what you want.
In the XCode documentation iPhone Application Programming Guide there is a section on "Moving Content That Is Located Under the Keyboard" that talks about receiving keyboard notifications when a keyboard is about to show. There's code there to show you how to get the keyboard size (which varies depending on the orientation). I won't repeat it here.
You can use the same technique to get the UIKeyboardWillShowNotification notification and get the height of where the keyboard will end up. That gives you the bottom edge of where your view needs to go, effectively putting it above the keyboard. So just put your textbox and button inside a view. When you get the notification tell your view where it needs to go (keyboard height + height of the container view) and you're done. You'll also want to catch UIKeyboardWillHideNotification to move the view back to where it was, so keep track of the original container view position.
It's pretty straightforward and it'll look nice, especially if you use a nice UIView animation effect and set the timing just right.