- (void)viewDidLoad {
[super viewDidLoad];
[self layoutScreens];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
-(void)keyboardWillHide:(NSNotification *)notification{
NSDictionary *userInfo = notification.userInfo;
NSTimeInterval timeInterval = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
NSUInteger option = [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue];
[UIView animateWithDuration:timeInterval delay:0 options:option animations:^{
[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view layoutIfNeeded];
} completion:nil];
}
- (void)keyboardWillShow:(NSNotification *)notification{
NSDictionary *userInfo = notification.userInfo;
CGRect endFrame = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat keyBoardHeight = endFrame.size.height;
if (origonHeight > keyBoardHeight) {
return;
}
NSTimeInterval timeInterval = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
NSUInteger option = [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue];
[UIView animateWithDuration:timeInterval delay:0 options:option animations:^{
[self.view setFrame:CGRectMake(0, origonHeight-keyBoardHeight, self.view.frame.size.width, self.view.frame.size.height)];
[self.view layoutIfNeeded];
} completion:nil];
}
-(void)layoutScreens
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
//4.7inch
if (screenBounds.size.height == 667) {
_contrainerViewBottom.constant = 300;
}
//5.5inch
else if(screenBounds.size.height == 736){
_contrainerViewBottom.constant = 360;
}
//4.0inch
else if (screenBounds.size.height == 568){
_contrainerViewBottom.constant = 200;
}
//ipad
else if (screenBounds.size.height == 1024){
_contrainerViewBottom.constant = 460;
}
origonHeight = _contrainerViewBottom.constant-10;
_headLeftConstraints.constant = (screenBounds.size.width - 80)/2;
}