1
에서 iOS 5의 Messages.app 키보드 액세서리보기 동작
는 아무도 내가 실제로 액세서리보기로 생각하지 않는 최적의 동작에게 "액세서리보기"(반전 쉼표 년대 를 에뮬레이션하는 방법을 설명 할 수) iOS 5의 Messages.app에서 키보드의 상단에 고정되어 있지만 키보드를 닫을 때 화면에 남아있는 느낌을주는보기를 원합니다.
에서 iOS 5의 Messages.app 키보드 액세서리보기 동작
는 아무도 내가 실제로 액세서리보기로 생각하지 않는 최적의 동작에게 "액세서리보기"(반전 쉼표 년대 를 에뮬레이션하는 방법을 설명 할 수) iOS 5의 Messages.app에서 키보드의 상단에 고정되어 있지만 키보드를 닫을 때 화면에 남아있는 느낌을주는보기를 원합니다.
아마도 키보드 애니메이션과 동일한 지속 시간을 갖는 애니메이션을 사용하여 다시 배치되는 별도의보기 일 것입니다.
UIKeyboardWillShowNotification 및 UIKeyboardWillHideNotification을 관찰하고 처리기에서 키보드의 애니메이션 지속 시간과 프레임을 가져 와서 자신의 애니메이션을 시작하여 키보드와 함께 움직이는 것처럼 보이게 배치하십시오. 내가 사용하는 유사한 코드는 다음과 같습니다.
- (void)registerKeyboardNotifications {
// Register for keyboard notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)unregisterKeyboardNotifications {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)keyboardWillShow:(NSNotification*)aNotification {
NSDictionary* info = [aNotification userInfo];
CGRect kbFrameBeginFrame = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
CGRect kbFrameEndFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
NSTimeInterval animDuration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
UIViewAnimationCurve animCurve = [[info objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];
NSLog(@"\nFrame Begin = %@\nFrame End = %@\nAnimation Duration = %f\nAnimation Curve = %i",
NSStringFromCGRect(kbFrameBeginFrame), NSStringFromCGRect(kbFrameEndFrame), animDuration, animCurve);
_showKeyboard = YES;
[self adjustUIForKeyboard:kbFrameEndFrame.size animDuration:animDuration];
}
- (void)keyboardWillHide:(NSNotification*)aNotification {
NSDictionary* info = [aNotification userInfo];
CGRect kbFrameBeginFrame = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
CGRect kbFrameEndFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
NSTimeInterval animDuration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
UIViewAnimationCurve animCurve = [[info objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];
NSLog(@"\nFrame Begin = %@\nFrame End = %@\nAnimation Duration = %f\nAnimation Curve = %i",
NSStringFromCGRect(kbFrameBeginFrame), NSStringFromCGRect(kbFrameEndFrame), animDuration, animCurve);
_showKeyboard = NO;
[self adjustUIForKeyboard:kbFrameEndFrame.size animDuration:animDuration];
}
/**
* Adjust the UI elements so that views are visible when keyboard is visible or hidden
*/
- (void)adjustUIForKeyboard:(CGSize)keyboardSize animDuration:(NSTimeInterval)duration {
[UIView animateWithDuration:duration
animations:^(void) {
// When keyboard is showing we adjust up and vice versa for a hidden keyboard
if (_showKeyboard) {
// Set your view's frame values
} else {
// Set your view's frame values
}
}
completion:NULL];
}
최고! 여기서 중요한 것은 알림에서 키보드 애니메이션 세부 정보를 추출 할 수 있다는 사실을 깨닫지 못했다는 것입니다. 고마워. –
"철자를 지어 주셔서"고맙습니다. – Morkrom