As the keyboard pops up, the response view is also moved up.
Sometimes you may encounter such a situation, such
In this way, the pop-up keyboard blocks the text box, so that you cannot see the text box, and you cannot see what you entered.
There are two ways to solve this problem
1. Adjust the text box to a high point so that the keyboard will not block the text box, but sometimes the layout cannot do this,
It is obvious that this method is not desirable,
2. Move the entire view up when the keyboard is to pop up, so that the text box will move up.
Obviously, this method is more desirable. Next we will implement this method.
We implement CGAffineTransform through an affine transformation.
If you are not familiar with the affine transform, you can refer to another article I wrote. below is the link
Http://blog.csdn.net/lc_obj/article/details/17454825
First, implement the method called when you click the text box to enter the content
// The method called to start Editing the content of the text box. Use the drag-and-drop association method. The response is Editing Did Begin.
-(IBAction) editBegin :( id) sender {
// Create a thread to delay the view
NSThread * thread = [[NSThread alloc] initWithTarget: self selector: @ selector (change :) object: nil];
[Thread start];
// Release the created object
[Thread release];
}
-(Void) change :( id) sender
{
// Thread sleep for 0.2 seconds to realize view Delay
[NSThread sleepForTimeInterval: 0.2];
// Create an affine transform. The translation (0,-100) view is moved up by 100 pixels.
CGAffineTransform pTransform = CGAffineTransformMakeTranslation (0,-100 );
// Use this transform for the view
Self. view. transform = pTransform;
}
Here, I will be wondering why the view is directly moved up in the-(IBAction) editBegin :( id) sender method,
Instead, you have to create another thread and then respond to a method for implementation.
In fact, I did this at the beginning, but I found a BUG that could not be said to be a BUG,
In that way, when you click the text box at the beginning, the view immediately moves up, and the speed is very fast,
Maybe you will say that this is not exactly what we want. Yes, it is indeed what we want, but the problem is, at this moment
The keyboard just pops up. That is to say, when the keyboard pops up, the view is moved.
There is a black area, which may be between 0.1 and 0.2 seconds. Although there is no big problem, it always feels like
The picture is not so harmonious, so I use the sleep thread method to delay the view's move up.
I may not explain it clearly. In fact, you can try it yourself.
The following is the processed
Download the demo of the previous article. The demo of the previous article implements this function.
Here is the link to the demo: http://download.csdn.net/detail/u012884714/6774115
This is just an implementation of small function details. Here we will share it with you-LC