The UIScrollView editing box is displayed with keyboard occlusion.
When a row in UIScrollView has an editing box, click the edit box. The pop-up keyboard may block the editing box, resulting in poor experience. The solution is simple, that is, to increase the distance between the content of UIScrollView and the inner margin of the UIScrollView container (precisely the bottom margin), which is exactly the keyboard height, the ios system will relocate the selected row, which is exactly the same distance from the bottom of the window. Of course, when you scale back the keyboard, pay attention to setting the padding. The most important function involved is the setContentInset function of UIScrollView.
First, register the keyboard pop-up and scaled back notification listening at the beginning of the program: [[nsicationicationcenter defaultCenter] addObserver: self selector: @ selector (keyboardWillShow :) name: UIKeyboardWillShowNotification object: nil];
[[Nsicationcenter center defacenter center] addObserver: self selector: @ selector (keyboardWillHide :) name: UIKeyboardWillHideNotification object: nil];
The implementation of keyboardWillShow and keyboardWillHide is as follows:
-(Void) keyboardWillShow :( NSNotification *) notification
{
// Frame after keyboard pop-up
NSValue * keyboardBoundsValue = [[notification userInfo] objectForKey: UIKeyboardFrameEndUserInfoKey];
CGRect keyboardBounds;
[KeyboardBoundsValue getValue: & keyboardBounds];
// Set the new padding, which is the distance between the last row of UIScrollView and the bottom border of UIScrollView,
// When this function is triggered, the system sets the distance from the selected row to the bottom edge of the window to this value, so that it is not covered by the keyboard.
UIEdgeInsets e = UIEdgeInsetsMake (0, 0, keyboardBounds. size. height, 0 );
[[Self tableView] setContentInset: e];
// Adjust the distance between the slide bar and the bottom edge of the window
[[Self tableView] setScrollIndicatorInsets: e];
}
-(Void) keyboardWillHide :( NSNotification *) notification
{
// After the keyboard is scaled back, the settings are restored.
UIEdgeInsets e = UIEdgeInsetsMake (0, 0, 0, 0 );
[[Self tableView] setScrollIndicatorInsets: e];
[[Self tableView] setContentInset: e];
}
As follows:
Before the pop-up:
After the pop-up: