键盘消失后 UIPopoverController 的视图控制器会调整大小

发布于 2024-10-26 15:21:07 字数 139 浏览 5 评论 0原文

我在 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

又爬满兰若 2024-11-02 15:21:24

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

我解决这个问题的方法是观察键盘在控制 UIPopoverController 的控制器中消失:

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

然后在 -presentSearchPopover 中,再次呈现 UIPopoverController (这是一个相当无缝的过渡):

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

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

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

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

    [super dealloc];
}

Had this problem myself recently.

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];

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];
}

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

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

    [super dealloc];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文