即使在呈现模态视图控制器时,如何保持键盘存在? [英] How can I keep the keyboard present even when presenting a modal view controller?

查看:102
本文介绍了即使在呈现模态视图控制器时,如何保持键盘存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模态视图控制器,并且UITextView成为第一个响应者并显示键盘。

I've got a modal view controller that is presented and a UITextView becomes the first responder and the keyboard is shown.

加载此屏幕后,用户可以在提交之前对其输入进行分类。
这是通过顶部显示的另一个模态视图控制器发生的。

Once this screen is loaded, the user can categorize their input before submitting it. This happens by way of another modal view controller that is presented on top.

当出现第二个时,键盘被解除,用户选择,然后当初始UITextView再次成为第一响应者时重新出现。

When this second one is presented, the keyboard is dismissed, the user chooses, and then reappears when the initial UITextView becomes first responder again.

如何在不解除键盘的情况下呈现第二个模态视图控制器?

How can I present the second modal view controller without ever dismissing the keyboard?

编辑:我已经实现了部分UITextViewDelegate,但我仍然没有得到理想的结果。

I've implemented part of the UITextViewDelegate, and I'm still not getting the desired result.

- (BOOL)textViewShouldEndEditing:(UITextView *)textView {
    return NO;
}


推荐答案

你不能这样做使用 presentModalViewController:animated:。您必须将模态视图放在单独的UIWindow中,将第二个UIWindow的windowLevel设置为高(如UIWindowLevelStatusBar),并在屏幕上自动设置动画。您根本不需要第二个视图控制器。

You can't do this using presentModalViewController:animated:. You'll have to put your modal view in a separate UIWindow, set that second UIWindow's windowLevel to something high (like UIWindowLevelStatusBar), and animate it on and off the screen yourself. You won't need a second view controller at all.

在您的XIB中,创建一个新的顶级UIWindow对象。将第二个视图放入此窗口。将窗口连接到视图控制器上的插座。 (我在我的测试代码中调用了插座 otherWindow ,但是 overlayWindow 将是一个更好的名称。需要声明插座 strong retain 。)

In your XIB, make a new top-level UIWindow object. Put your second view into this window. Connect the window to an outlet on your view controller. (I called the outlet otherWindow in my test code but overlayWindow would be a better name. The outlet needs to be declared strong or retain.)

在视图控制器中,实现这些方法:

In your view controller, implement these methods:

- (IBAction)presentOverlay:(id)sender
{
    CGRect frame = [UIScreen mainScreen].applicationFrame;
    frame.origin.y += frame.size.height;
    self.otherWindow.frame = frame;
    self.otherWindow.windowLevel = UIWindowLevelStatusBar;
    self.otherWindow.hidden = NO;
    [UIView animateWithDuration:.25 animations:^{
        self.otherWindow.frame = [UIScreen mainScreen].applicationFrame;
    }];
}

- (IBAction)dismissOverlay:(id)sender
{
    [UIView animateWithDuration:.25 animations:^{
        CGRect frame = [UIScreen mainScreen].applicationFrame;
        frame.origin.y += frame.size.height;
        self.otherWindow.frame = frame;
    } completion:^(BOOL completed){
        self.otherWindow.hidden = YES;
    }];
}

使用这些来显示和关闭叠加视图。

Use these to present and dismiss the overlay view.

这篇关于即使在呈现模态视图控制器时,如何保持键盘存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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