I'm new to ios app development. In a sample login page there are many view objects in a view.When i try to edit the textfields at the bottom of the screen, the keyboard is appeared and it is over the view object that i need to edit.So, the view object is covered with keyboard itself. How to view all the view objects at the bottom of the screen properly even if keyboard is appeared.? Thanks in Advance.
Asked
Active
Viewed 54 times
0
-
What you want? both visible at the same time in the same place? – Anoop Vaidya Mar 17 '13 at 02:14
1 Answers
0
Add scroll view,display your controls on it, add the Keyboard notification,adjust the scroll contents.
A good documents is available here
- (void)viewDidLoad
{
@try
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
@catch (NSException *exception)
{
NSLog(@"%s\n exception: Name- %@ Reason->%@", __PRETTY_FUNCTION__,[exception name],[exception reason]);
}
}
- (void)keyboardWasShown:(NSNotification *)notification
{
@try
{
// Step 1: Get the size of the keyboard.
CGSize keyboardSizePotriat = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
CGSize keyboardSize = {keyboardSizePotriat.height,keyboardSizePotriat.width};
// Step 2: Adjust the bottom content inset of your scroll view by the keyboard height.
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height, 0.0);
self.theScrollView.contentInset = contentInsets;
self.theScrollView.scrollIndicatorInsets = contentInsets;
CGPoint scrollPoint = CGPointMake(0.0, self.txtMRN.frame.origin.y - (keyboardSize.height - 45));
[self.theScrollView setContentOffset:scrollPoint animated:YES];
}
@catch (NSException *exception)
{
NSLog(@"%s\n exception: Name- %@ Reason->%@", __PRETTY_FUNCTION__,[exception name],[exception reason]);
}
}
- (void) keyboardWillHide:(NSNotification *)notification
{
@try
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
self.theScrollView.contentInset = contentInsets;
self.theScrollView.scrollIndicatorInsets = contentInsets;
}
@catch (NSException *exception)
{
NSLog(@"%s\n exception: Name- %@ Reason->%@", __PRETTY_FUNCTION__,[exception name],[exception reason]);
}
}

Shamsudheen TK
- 30,739
- 9
- 69
- 102