java board 大小调整_UIKeyboardDidShowNotification多次调用,有时键盘尺寸不正确

我试图在键盘出现/更改时在键盘上方移动UITextView . 让's say I have the English keyboard displaying and then switch directly to the Chinese keyboard (which is taller than the standard English keyboard). In this scenario my text view always appears too high (to the naked eye, it looks like the text view is incorrectly offset by the size of the Chinese keyboard 2448143 . I'发布一张图片但缺乏声誉:)) . 当我的应用程序收到UIKeyboardDidShowNotification(使用UIKeyboardFrameEndUserInfoKey获取高度)时,我正在调整我的文本视图位置,并且经过一些调查 UIKeyboardDidShowNotification is called multiple times, oftentimes with the incorrect keyboard dimensions (我在响应UIKeyboardDidShowNotification的方法中使用了NSLogged 'self',它实际上始终是相同的View Controller宾语 .

但是,即使多次触发此通知,我仍然不明白为什么某些通知的键盘高度会有所不同 . 其中一个通知始终具有正确的高度,但是当它不是最后一个通知时,文本视图最终会出现在错误的位置 . 任何有关如何进一步排除故障的见解将非常感激!

编辑:我测试的越多,特别是中文键盘的问题就越多 . 每当我将键盘从英文切换到中文时,我得到三个UIKeyboardWillShowNotifications:

2014-12-24 22:49:29.385 Example[1055:421943] info dictionary: {

UIKeyboardAnimationCurveUserInfoKey = 0;

UIKeyboardAnimationDurationUserInfoKey = 0;

UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 252}}";

UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 460}";

UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 442}";

UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 352}, {320, 216}}";

UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 316}, {320, 252}}";

}

2014-12-24 22:49:29.408 Example[1055:421943] info dictionary: {

UIKeyboardAnimationCurveUserInfoKey = 0;

UIKeyboardAnimationDurationUserInfoKey = 0;

UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 216}}";

UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 442}";

UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 460}";

UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 316}, {320, 252}}";

UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 352}, {320, 216}}";

}

2014-12-24 22:49:29.420 Example[1055:421943] info dictionary: {

UIKeyboardAnimationCurveUserInfoKey = 0;

UIKeyboardAnimationDurationUserInfoKey = 0;

UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 288}}";

UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 442}";

UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 424}";

UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 316}, {320, 252}}";

UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 280}, {320, 288}}";

}

第一个具有正确的结束高度:252 . 然而,接下来的两个在216和288处是不正确的 . 这可靠地发生 .

以下是一些片段,用于演示我如何管理订阅通知:

-(void)viewWillAppear:(BOOL)animated {

[super viewWillAppear:animated];

[self registerForKeyboardNotifications];

}

-(void)viewWillDisappear:(BOOL)animated {

[super viewWillDisappear:animated];

[[NSNotificationCenter defaultCenter] removeObserver:self

name:UIKeyboardWillHideNotification

object:nil];

[[NSNotificationCenter defaultCenter] removeObserver:self

name:UIKeyboardDidShowNotification

object:nil];

}

- (void)registerForKeyboardNotifications {

[[NSNotificationCenter defaultCenter] addObserver:self

selector:@selector(keyboardDidHide:)

name:UIKeyboardWillHideNotification object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self

selector:@selector(keyboardDidShow:)

name:UIKeyboardDidShowNotification object:nil];

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值