键盘滑回后,UIPopoverController不会移动到原始位置 [英] UIPopoverController not moving to original position after keyboard slides back down

查看:105
本文介绍了键盘滑回后,UIPopoverController不会移动到原始位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iPad上用UINavigation栏显示一个popover。在第二个视图中,我有一个可以显示键盘的UISearchController。键盘向上推动弹出窗口,这很好,但是如果我现在按下UINavigation条上的后退按钮它会解除键盘,这很好,但弹出窗口不会滑回原来的位置。有谁知道如何解决这个问题?谢谢!

I'm displaying a popover in iPad with a UINavigation bar. On the second view, I have a UISearchController that can display a keyboard. The keyboard pushes the popover up, which is fine, however if I now push the 'back' button on the UINavigation bar it dismisses the keyboard which is fine, but the popover doesn't slide back down to its original position. Anyone know how to fix that? Thanks!

推荐答案

好的,所以我真的想通了(我相信)你的问题是什么......以防万一从谷歌偶然发现这一点,我想我会回答我是怎么做到的。这感觉就像一个黑客工作,但我还没有找到任何其他方法来做到这一点。

Ok so I actually figured out (I believe) what your question was asking...and just in case anyone stumbles upon this from google, I figured I'd answer how I did it. It feels like a hack job but I haven't been able to find any other way to do it.

在调出键盘的控制器中,我发布了它键盘解除时的通知:

In the controller that brings up the keyboard,I had it post a notification whenever the keyboard dismisses:

    [aTextField resignFirstResponder];
[[NSNotificationCenter defaultCenter] postNotificationName:@"movePopups" object:nil];

然后回到控制UIPopover的主屏幕控制器上,我添加了一个监听器:

Then back on my home screen controller, that controls the UIPopover, I added a listener:

    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(movePopUpToRightLocation)
                                             name:@"movePopups"
                                           object:nil];    

。请务必记住删除dealloc中的监听器以获得良好的编程习惯:

inside the init. Be sure to remember to remove the listener in your dealloc for good programming practice:

[[NSNotificationCenter defaultCenter] removeObserver:self];

那么每当我收到键盘消失的通知时,我都会看到弹出窗口的按钮的引用显示,直接从它重新出现:

So then whenever I get notification that the keyboard disappears, I get a reference to the button that the popover shows up from, and just have it re-appear directly from it:

-(void)movePopUpToRightLocation {
NSLog(@"move pop up to right location");
if (morePopUp) {
    UIBarButtonItem *barButtonItem = (UIBarButtonItem *)[[bottomToolBar items] objectAtIndex:0];
    [morePopUp presentPopoverFromBarButtonItem:barButtonItem
                      permittedArrowDirections:UIPopoverArrowDirectionDown
                                      animated:YES];            
}   

}

我没有添加任何检查弹出窗口,但如果我有多种类型的弹出窗口/按钮,我可以很容易地做到这一点。但这是你可以去的基本前提。

I haven't added any checks for which popup it is, but I can easily do that if I have more than 1 type of popover / button that it would appear from. But that's the basic premise that you can go from.

希望它有所帮助!

这篇关于键盘滑回后,UIPopoverController不会移动到原始位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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