키보드가 위로 올라 갔을 때 높이 변경을 애니메이션으로 표시하려고하는보기가 있습니다 (아래 표시된 코드). 프레임 변경을 호출하는 뷰는 완벽하게 애니메이션입니다. 그러나이보기에는 하위보기가 포함되어 있으며이보기에는 키보드가 나타나는 텍스트 필드가 포함되어 있으며 이러한 하위보기는 애니메이션 대신 새 위치로 점프하고 있습니다. 하위 뷰에 자동 레이아웃 제약 조건을 넣어 수퍼 뷰의 왼쪽, 아래 및 오른쪽으로 제한하고 일정한 높이를 유지합니다. 여기iOS - 서브 프레임이 프레임 변경으로 애니메이션되지 않습니다.
예 비디오 : http://youtu.be/EmcZ-cXeTbM
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slideViewForKeyboard:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slideViewForKeyboard:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)slideViewForKeyboard:(NSNotification *)note {
NSDictionary* userInfo = [note userInfo];
// Get animation info from userInfo
NSTimeInterval animationDuration;
UIViewAnimationCurve animationCurve;
CGRect keyboardEndFrame;
[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
[[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
[[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];
CGRect newFrame = CGRectMake(self.view.frame.origin.x,
self.view.frame.origin.y,
self.view.frame.size.width,
keyboardEndFrame.origin.y);
[UIView animateWithDuration:0 delay:0 options:(animationCurve << 16) animations:^{
[self.view setFrame:newFrame];
}completion:^(BOOL completed){}];
}
- (IBAction)endEditingOnTap:(UITapGestureRecognizer *)sender {
[self.view endEditing:YES];
}
@end
감사합니다. -layoutIfNeeded는 내가 필요한 것입니다. (animationDuration은 코드를 SO로 바꿨을 때 오타 였지만 그 캐치에도 감사드립니다!) –