#pragma mark -view自动调整位置
- (void)changeContentViewPosition:(NSNotification *)notification{
UIWindow *window = [[[UIApplication sharedApplication]delegate]window];
[window setBackgroundColor:[UIColor whiteColor]];
NSDictionary *dict = [notification userInfo];
NSValue *value = [dict objectForKey:UIKeyboardFrameEndUserInfoKey];
CGFloat keyboardHeight = value.CGRectValue.size.height;
NSNumber *duration = [dict objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSNumber *curve = [dict objectForKey:UIKeyboardAnimationCurveUserInfoKey];
if (self.nameText.isFirstResponder) {
}else if(self.wayText.isFirstResponder){
CGFloat offsetTop = viewHeight - CGRectGetMaxY(self.wayHolder.frame);
if (offsetTop < keyboardHeight) {
offsetTop = offsetTop - keyboardHeight;
[UIView animateWithDuration:duration.floatValue animations:^{
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:curve.intValue];
self.view.frame = CGRectMake(0, offsetTop, self.view.frame.size.width, self.view.frame.size.height);
}];
}
}else if (self.integralText.isFirstResponder){
CGFloat offsetTop = viewHeight - CGRectGetMaxY(self.integralHolder.frame);
if (offsetTop < keyboardHeight) {
offsetTop = offsetTop - keyboardHeight;
[UIView animateWithDuration:duration.floatValue animations:^{
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:curve.intValue];
self.view.frame = CGRectMake(0, offsetTop, self.view.frame.size.width, self.view.frame.size.height);
}];
}
}else if (self.addressText.isFirstResponder){
CGFloat offsetTop = viewHeight - CGRectGetMaxY(self.addressHolder.frame);
if (offsetTop < keyboardHeight) {
offsetTop = offsetTop - keyboardHeight;
[UIView animateWithDuration:duration.floatValue animations:^{
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:curve.intValue];
self.view.frame = CGRectMake(0, offsetTop, self.view.frame.size.width, self.view.frame.size.height);
}];
}
}else if (self.declareTextView.isFirstResponder){
CGFloat offsetTop = -keyboardHeight+64;
[UIView animateWithDuration:duration.floatValue animations:^{
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:curve.intValue];
self.view.frame = CGRectMake(0, offsetTop, self.view.frame.size.width, self.view.frame.size.height);
}];
}
}
#pragma mark -keyboardWillHide
- (void)resumeContentViewPosition:(NSNotification *)notification{
NSDictionary *dict = [notification userInfo];
NSNumber *duration = [dict objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSNumber *curve = [dict objectForKey:UIKeyboardAnimationCurveUserInfoKey];
[UIView animateWithDuration:duration.doubleValue animations:^{
[UIView setAnimationCurve:curve.intValue];
self.view.frame = CGRectMake(0, viewOriginY, self.view.frame.size.width, self.view.frame.size.height);
}];
}