Skip to content

Instantly share code, notes, and snippets.

@nishitpatel
Last active July 1, 2017 13:48
Show Gist options
  • Save nishitpatel/06141cd421725d717e1ba933189bb5b4 to your computer and use it in GitHub Desktop.
Save nishitpatel/06141cd421725d717e1ba933189bb5b4 to your computer and use it in GitHub Desktop.
Auto Scroll whenever keyboard appears for TextField using UIScrollView
Step 1: Create UI Using UIScrollView (Pur all your elements inside UIScrollView)
Step 2: Implement UITextFieldDelege to UIViewController<UITextFieldDelegate>
Integrate Below code into controller.m file
-(void) viewDidLoad{
self.textField.deleget = self;
}
- (void) scrollViewAdaptToStartEditingTextField:(UITextField*)textField{
CGPoint point = CGPointMake(0, (textField.frame.origin.y - 1.5) + (textField.frame.size.height + 200));
[self.scrollView setContentOffset:point animated:YES];
}
- (void) scrollVievEditingFinished:(UITextField*)textField{
CGPoint point = CGPointMake(0, textField.frame.origin.y);
[self.scrollView setContentOffset:point animated:YES];
}
- (BOOL) textFieldShouldBeginEditing:(UITextField *)textField{
[self scrollViewAdaptToStartEditingTextField:textField];
return YES;
}
- (BOOL) textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
[self scrollVievEditingFinished:textField];
return YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment