Last active
July 1, 2017 13:48
-
-
Save nishitpatel/06141cd421725d717e1ba933189bb5b4 to your computer and use it in GitHub Desktop.
Auto Scroll whenever keyboard appears for TextField using UIScrollView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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