有一个UITextView视图。 UITextView是键盘唯一可能的firstResponder。我们称之为“BackView”。
另一个视图是PopUp(具有透明背景的全屏视图,其淡化底层视图)。我们称之为“PopUp”。
PopUp工作正常,除非键盘在屏幕上。呈现PopUp强制键盘被隐藏,当PopUp被解除时,键盘再次显示。由于PopUp没有覆盖整个BackView,因此效果不佳。
在显示PopUp时,有没有办法在BackView上保持键盘? (弹出窗口无需使用键盘)。
PopUp包含:
PopUp显示为:
[self setModalPresentationStyle:UIModalPresentationCurrentContext];
[self presentViewController:vc animated:YES completion:nil];
找到解决方案
将PopUp视图添加为当前窗口的子视图
节目:
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
})
}
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];