UITextField, UIScrollView, UIKeyboard
– View controller in storyboard go to Show the atribute inspector set Simulated matrics Size iPhone 4-inch
– Add UISCrollView x = 0, y = 0, Width = 320, Height = 568
– Add pin add new Constraints Top = 0,Down = 0,Right = -20,Left = -20
add constraints
– Go to Autolayout seggestion – Update frame – Fix misplacement
– Add UIView(View size will be What ever you want) x = 0, y = 0, Width = as per ScrollView (Or whatever you want), Height = 768(whatever you want)
– Add pin add new constraints Top = 0,Down = -200,Right = 0,Left = 0 and Tick Height then add constraints
– Hold Command and cluck and drag mouse aero View to ScrollView and set Equal Width
– In Document out line open View constraints Select bottom = View.bottom and go to Right Side show the size inspector set constant 0(Zero)
– Drag and drop two label
Select Sign UP label
Set Constraints Centre horizontaly in container
Add pin top, Width, Height
Click Drag and Drop from First name Textfield to abow label
Select Center Horizontally
Add pin top, Width
Click drag and drop from last name textfield to first name textfield
select Centre Horizontally
Add pin top, Width
Do same thing to Set constraints for all textfield
Click drag and drop from last name Submit button to country textfield
select Centre Horizontally
Add pin top, Width, Height
Set IBOutlet for ScrollView named
Set IBOutlet for all Textfield
Set tag for all Textfield
Set delegate for all Textfield
ViewController.h
<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *currentTextField;
ViewController.m
– (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
UITapGestureRecognizer *aGest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected)];
aGest.numberOfTapsRequired = 1;
[self.ScrlViewSignUpVC addGestureRecognizer:aGest];
// Do any additional setup after loading the view, typically from a nib.
}
– (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
}
#pragma mark – Gester method
– (void)tapDetected {
[self.currentTextField resignFirstResponder];
}
#pragma mark – UIKeyboard show/hide notification
– (void)keyboardWillShow:(NSNotification *)iNotification {
NSLog(@”%f”, [iNotification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height);
NSDictionary *aKeyInfo = iNotification.userInfo;
NSValue *aRectValue = [aKeyInfo valueForKey:UIKeyboardFrameBeginUserInfoKey];
CGRect aRect = [aRectValue CGRectValue];
if (self.currentTextField.tag == 5 || self.currentTextField.tag == 6 || self.currentTextField.tag == 7) {
self.ScrlViewSignUpVC.contentOffset = CGPointMake(0, (aRect.size.height) – 50);
}
}
– (void)keyboardWillHide:(NSNotification *)iNotification {
self.ScrlViewSignUpVC.contentOffset = CGPointMake(0, 0);
}
#pragma mark – UITextField delegate
– (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
– (void)textFieldDidBeginEditing:(UITextField *)textField {
self.currentTextField = textField;
}