首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSNotificationCenter

NSNotificationCenter
EN

Stack Overflow用户
提问于 2012-04-04 17:33:24
回答 1查看 450关注 0票数 1

现在,我正在尝试写一个函数,当键盘出现在屏幕上时,将帧上移。我开始使用NSNNotificationCenter。我的代码工作正常,但不正确。当键盘出现时,我的formView正在向上移动,但当我开始在formView中编辑下一个textField时,formView再次向上移动。我的代码出了什么问题?谢谢。

代码语言:javascript
复制
- (void)keyboardWillShow:(NSNotification *) aNotification {
    NSDictionary *userInfo = [aNotification userInfo];

    CGRect frame = self.formView.frame;
    frame.origin.y -= 170;

    NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
    NSTimeInterval animationDuration;

    [animationDurationValue getValue:&animationDuration];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:animationDuration];

    formView.frame = frame;

    [UIView commitAnimations];

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-04 17:53:59

当键盘消失时,您应该再次将170像素(或Mike建议的任何计算方法)添加到视图的origin.y中。当你点击另一个文本字段时,从技术上讲,当前的键盘将消失(你的视图没有任何反应),一个新的键盘将出现(你的keyboardWillShow将再次被调用,你再次将你的视图向上移动170px)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10008497

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档