How to make the textfield move up when keyboard covers it up - iphone

I have an application in which I have 2 textfields and a textview. When I click on the first textfield my keyboard popsup and theirs is no problem but when I type in the second textfield my keyboard popsup and covers the textfield.
I want that when I click on the second text field, the textfield should move up little bit so that I can type in and I have a textview. But I have written code for textview so that when I type in textview it automatically moves.
The problem is with textfield. How can I solve this problem?

Consider using a UITableViewController. Otherwise implement UITextFieldDelegate and move your UIView to the desired position in the - (void)textFieldDidBeginEditing:(UITextField *)textField method.

Check out the link below - the solution is written by Micheal Tyson. It addresses UITableView and UIScrollView, can be easily changed and works just as a drop-in component. I'm using it and it works well.
A drop-in universal solution for moving text fields out of the way of the keyboard

Create two methods like given below , first one is for bringing the view slightly upwards, and second one is to bring the view to its original position back
First method:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.3];
self.view.transform = CGAffineTransformTranslate(self.view.transform, 0, -175);
[UIView commitAnimations];
Second method:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.3];
self.view.transform = CGAffineTransformTranslate(self.view.transform, 0, 175);
[UIView commitAnimations];
[self.destext resignFirstResponder];
Call these methods on textfieldEditingDidbegin and DidEndonExit

Add the view to a UIScrollView. Then use the UITextFieldDelegate methods to set the contentOffset of the scrollView when textField is tapped. Reset the contentOffset when the user has finished entering text.

I have created a simple subclass of UIView containing UITextView and a send button that moves up when keyboard shows and moves down when keyboard hides. In addition to that, UITextView resizes according to the amount of text in it.
Have a look at here:
https://github.com/kerrygrover/KBTextView

An obvious one that you've probably tried already, but one that took me a while to latch onto, is to change from landscape to portrait.

Related

How to tune the onFocus auto scroll distance?

I am trying to tune the auto scroll distance of the default IOS behaviour.
As shown in the picture, by default, the screen will scroll automatically up so that the key board won't hide the section you are editing.
But the problem with this is that it only scrolls up high enough so that the top of the key board overlapping on the bottom of the cell.
What I want is something like this:
So instead of just moving up till the keyboard won't cover the textField, it should move up some extra space so that the next textField could be seen as well.
Ok, now I finish the description. Here is what I have tried.
1. I have tried to delegate the didSelectRowAtIndexPath to roll up the table view.
2. I have tried to use a tap gesture recognizer to handle the tapPosition and then scroll.
These two methods actually works to some extent but they are still not 100% what I want. Because once I tap focus on text field the table view still not moved high enough so that I can see the next field. (It seems to me that the textFields focus on event has higher priority than the tap gesture and cell selection)
Now this is what I want, I was wondering if there is a way to tune the default scroll up behaviour on focus of the text field.
Thanks.
Try this,
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
self.activeTextField = textField;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3f];
[self.scrollView setContentOffset:CGPointMake(0.0, self.activeTextField.frame.origin.y-92) animated:YES]; // change the value "92" as per your scroll height.
[UIView commitAnimations];
}

Keyboard appearing without animation on iOS 5

I have a popup view which I animate in the current view from the bottom using MJPopupViewController and there is a UITextField in that popup view. When I tap on that textfield, instead of animating from the bottom, the keyboard appears immediately. the popup view is a UIViewController and there is nothing fancy in it, no code related to the keyboard. i added observers to related keyboard notifications and saw that the UIKeyboardAnimationDurationUserInfoKey value is 0 even though it is the first time the keyboard is displayed in the app. the keyboard disappears with animation properly, only the animation of keyboard sliding in from bottom is broken. this occurs on iOS 5.0 and 5.1, the keyboard functions properly on iOS 6 +. i'm trying to track down the issue but right now i am out of clues. what causes UIKeyboardAnimationDurationUserInfoKey to be zero, for a start?
Try adding this.
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.view cache:YES];
[textField becomeFirstResponder];
[UIView commitAnimations];
}
PS: We need to set the delegate for this one.

Issue with animation of UITextView in a UIView

I have a setup in which I have my main UIView, within this I display another UIView which appears to slide & expand until fully in view. Within this new view I have a UITextView, however when I run the animation to make the UIView appear it doesn't seem to apply the animation to the UITextView. The effect of this is that the UITextView just appears in its final position straight away, the rest of the UIView then slides into place. Is there a way to make the animation apply to the widgets inside the view as well?
Here is the code I'm using at the moment.
[self.view addSubview:innerView];
[innerView setFrame:CGRectMake(29.5,127,261,0)];
[textView setFrame:CGRectMake(20,20,221,0)];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5.0];
[innerView setFrame:CGRectMake(29.5,127,261,275)];
[textView setFrame:CGRectMake(20,128,221,129)];
[UIView commitAnimations];
Please can someone help me out? I've been playing around with this problem for a long time now with no luck at all.
I had similar behavior in one of my apps. It was due to the autoresizingMask on a UITextView. Also make sure your top UIView does not have autoresizesSubviews option enable as it will influence the behavior of your UITextView on animation.

Scrolling screen upward to expose TextView above keyboard

I think I'm missing something obvious and would appreciate an answer.
I have a view with a 2-section grouped tableView, each section having one row and a textView, the heights of the rows 335 and 140. This allows for a box with nicely rounded corners to type text into when the keyboard appears (140 height section) and when the keyboard is dismissed, a nice box to read more text (notes); most of the time, use is without the keyboard.
I also added a toolbar at the bottom of the screen to scroll up above the keyboard. A button on the toolbar dismisses the keyboard. This last part works fine with the keyboard going up and down using a notification and the following code in a keyboardWillShow method:
[UIView beginAnimations:#"showKeyboardAnimation" context:nil];
[UIView setAnimationDuration:0.50];
self.view.frame = CGRectMake(self.view.frame.origin.x,
self.view.frame.origin.y,
self.view.frame.size.width,
self.view.frame.size.height - 216);
[UIView commitAnimations];
But with the above code, the 2 sections of the tableView remain unscrolled, only the toolbar and the keyboard move. With the following code (found both in previous posts), both the toolbar and the tableView sections move.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.50];
CGRect rect = self.view.frame;
rect.origin.y -= 216;
self.view.frame = rect;
[UIView commitAnimations];
Now I know that I have to tweak the numbers to get the everything as I want it but my first question is what is substantively different between the 2 sets of code that the sections move in the 2nd but not in the 1st? The toolbar also moves with the 2nd code.
The second question is, am I going to be able to scroll the smaller height section from off the screen to above the keyboard while at the same time moving the toolbar up just 216?
Thanks
I may be missing something here, but in the first piece of code, you are changing the height by 216. While on the 2nd piece of code, you are changing the origin of the entire view by 216 in the y-direction.
Depending on how you have the frame set in IB, the first piece of code might not move it if you don't allow it to move in that direction. Check your settings in the inspector window.
When you are saying "unscrolled" you are referring to them not changing location within the main view correct? This would be different than them actually scrolling (which you can do as well by changing scroll value).
You may want to check out the Hidden Drawer example here, since they push views in and out of the main view, sort of like a toolbar, and I think that is what you are asking. The whole "scrolling" thing is throwing me off though.
http://cocoawithlove.com/2009/05/intercepting-status-bar-touches-on.html
From memory, something like
tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight

UITableViewCell Custom Drawing and Animating when Entering Edit/Reorder Mode

I am trying to do something very similar to this post. Starting with Atebits Fast Scrolling in Tweetie post I have a UITableView subclass that does all of it's drawing in the drawRect: method of it's contentView. This works perfectly and is super fast. What I am trying to do now is animate the transition from editing to not-editing.
An example of what I am trying to achieve would be a situation with some text right aligned in the cell. When entering edit mode, the contentView shifts right to allow room for the editing control but the text shifts offscreen on the right as well. If I simply call [contentView setNeedsDisplay] in layoutSubviews I can readjust the right aligned text but it just jumps to it's new position.
How can I get the transition to animate?
Your layoutSubviews should look like this:
-(void)layoutSubviews {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
/* Change offsets here. */
[UIView commitAnimations];
}
You may also need to add to applicationDidFinishLaunching:
[UIView setAnimationsEnabled:YES];