防止在presentViewController上隐藏键盘(显示弹出窗口)

时间:2014-07-03 15:22:22

标签: ios7 keyboard uitextview

有一个UITextView视图。 UITextView是键盘唯一可能的firstResponder。我们称之为" BackView"。

另一个视图是PopUp(具有透明背景的全屏视图,其淡化底层视图)。我们称之为" PopUp"。

除非键盘在屏幕上,否则PopUp工作正常。呈现PopUp强制键盘被隐藏,当PopUp被解除时,键盘再次显示。由于PopUp没有覆盖整个BackView,因此效果不佳。

在显示PopUp时,有没有办法在BackView上保留键盘? (弹出窗口无需使用键盘。)

PopUp包含:

  • 全屏视图,背景设置为黑色,带alpha(淡入底层视图)
  • 多张图片,标签和关闭按钮。

PopUp显示为:

[self setModalPresentationStyle:UIModalPresentationCurrentContext];
[self presentViewController:vc animated:YES completion:nil];

找到解决方案:

将PopUp视图添加为当前窗口的子视图

2 个答案:

答案 0 :(得分:0)

显示:

if let popupVC = storyboard.instantiateViewControllerWithIdentifier("PopupVC") as? PopupVC
    {
        var frame = UIScreen.mainScreen().bounds
        frame.origin.y = frame.size.height
        overlayWindow = UIWindow(frame: frame)

        popupVC.overlayWindow = overlayWindow
        overlayWindow.windowLevel = UIWindowLevelAlert
        overlayWindow.rootViewController = popupVC

        overlayWindow.makeKeyAndVisible()

        UIView.animateWithDuration(0.3, animations:
        {
            self.overlayWindow.frame.origin.y = 0
        })
    }

在PopupVC中隐藏

 if let window = overlayWindow
    {
        UIView.animateWithDuration(0.3, animations: {
            window.frame.origin.y = window.frame.height
        }, completion: { (finished) -> Void in
            self.overlayWindow = nil
        })
    }

答案 1 :(得分:0)

mb.server回答了他自己的问题(我也有一个问题)。但我只想明确地为其他人的利益拼出代码:

//instantiate popUpVC, then
popUpVC.view.frame = [UIScreen mainScreen].bounds; //assuming you wish the popover to occupy the entire screen; adjust as needed
UIWindow* currentWindow = [[[UIApplication sharedApplication] windows] lastObject];
[currentWindow addSubview:popUpVC.view];