键盘消失后,UIPopoverController的视图控制器会调整大小 [英] UIPopoverController's view controller gets resized after keyboard disappears

查看:89
本文介绍了键盘消失后,UIPopoverController的视图控制器会调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UIPopoverController 中有一个视图控制器。当我为属于弹出窗口中的视图的文本字段打开键盘时,视图会调整大小以适应键盘。但是,当键盘被解除时,视图不会恢复到原始大小。

I have a view controller inside a UIPopoverController. When I open a keyboard for a text field that belongs to the view in the popover, the view resizes to accommodate the keyboard. However, the view doesn't go back to the original size when the keyboard is dismissed.

任何想法如何让它重新调整大小?

Any ideas how to get it to resize back to what it was?

推荐答案

最近我自己遇到过这个问题。

Had this problem myself recently.

我绕过它的方式是观察键盘在控制器中消失,控制器控制UIPopoverController:

The way I got around it was to observe the keyboard disappearing in the controller which controls the UIPopoverController:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(presentSearchPopover) name:UIKeyboardDidHideNotification object:nil];

然后在 -presentSearchPopover 中,出示再次UIPopoverController(这是一个非常无缝的过渡):

And then in -presentSearchPopover, present the UIPopoverController again (it's quite a seamless transition):

- (void)presentSearchPopover
{
    self.searchPopoverController.popoverContentSize = CGSizeMake(width, height);

    [self.searchPopoverController presentPopoverFromRect:someRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}

不要忘记删除中的观察者 - dealloc 或类似的:

Don't forget to remove the observer in -dealloc or similar too:

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidHideNotification object:nil];

    [super dealloc];
}

这篇关于键盘消失后,UIPopoverController的视图控制器会调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆