旋转后获取 iPad 屏幕键盘的大小
Posted
技术标签:
【中文标题】旋转后获取 iPad 屏幕键盘的大小【英文标题】:Getting the size of the iPad on-screen keyboard after rotation 【发布时间】:2010-10-04 21:31:21 【问题描述】:对于我为 iPad 设计的应用程序,我有一个滚动视图,其中包含一些文本字段/文本视图。为了让所有内容都可见,我调整了滚动视图的contentSize
属性以在底部添加一个缓冲区,该缓冲区对应于键盘与滚动视图重叠的程度。这是代码(这里有一些特定于应用程序的东西,但希望不要太多,以至于您无法理解它):
- (void)viewWillAppear:(BOOL)animated
[super viewWillAppear:animated];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
- (void)viewWillDisappear:(BOOL)animated
[super viewWillDisappear:animated];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc removeObserver:self name:nil object:nil];
- (void)keyboardWillShow:(NSNotification *)aNotification
NSValue *animationCurve = [[aNotification userInfo] valueForKey:UIKeyboardAnimationCurveUserInfoKey];
UIViewAnimationCurve curve;
[animationCurve getValue:&curve];
NSValue *animationDuration = [[aNotification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval duration;
[animationDuration getValue:&duration];
NSValue *endingFrame = [[aNotification userInfo] valueForKey:UIKeyboardFrameEndUserInfoKey];
CGRect frame;
[endingFrame getValue:&frame];
[UIView beginAnimations:@"keyboardWillShow" context:bodyView];
[UIView setAnimationCurve:curve];
[UIView setAnimationDuration:duration];
// Re-draw code here.
[UIView commitAnimations];
- (void)keyboardWillHide:(NSNotification *)aNotification
NSValue *animationCurve = [[aNotification userInfo] valueForKey:UIKeyboardAnimationCurveUserInfoKey];
UIViewAnimationCurve curve;
[animationCurve getValue:&curve];
NSValue *animationDuration = [[aNotification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval duration;
[animationDuration getValue:&duration];
[UIView beginAnimations:@"keyboardWillHide" context:bodyView];
[UIView setAnimationCurve:curve];
[UIView setAnimationDuration:duration];
// Re-draw code here
[UIView commitAnimations];
我的问题是:在旋转过程中如何处理键盘大小?旋转 iPad 时我没有收到任何键盘通知,但键盘的大小发生了显着变化。理想情况下,我只需通过键盘在横向模式下重叠的量来调整 contentSize
属性的高度,但是如果不对键盘在两个方向上的高度进行硬编码,我就看不到这样做的好方法,这我不想做。
【问题讨论】:
查看***.com/questions/5150794/… 【参考方案1】:我偶然发现了这个调试的答案。事实证明,当 iPad 从纵向旋转到横向时,纵向键盘在横向键盘出现之前隐藏(并发送其通知)(并发送 its 通知)。因此,只要您考虑到这一点,就可以了。
【讨论】:
以上是关于旋转后获取 iPad 屏幕键盘的大小的主要内容,如果未能解决你的问题,请参考以下文章