我已经显示了一个模态视图控制器,并且 UITextView 成为第一响应者并显示键盘。
加载此屏幕后,用户可以在提交之前对其输入进行分类。
这是通过顶部呈现的另一个模态视图控制器来实现的。
当第二个出现时,键盘将消失,用户进行选择,然后当初始 UITextView 再次成为第一响应者时重新出现。
如何在不关闭键盘的情况下呈现第二个模态视图控制器?
编辑:我已经实现了 UITextViewDelegate 的一部分,但仍然没有得到所需的结果。
- (BOOL)textViewShouldEndEditing:(UITextView *)textView {
return NO;
}
你不能使用presentModalViewController:animated:
。您必须将模态视图放在一个单独的 UIWindow 中,将第二个 UIWindow 的 windowLevel 设置为较高的值(例如 UIWindowLevelStatusBar),然后自己在屏幕上和屏幕外设置动画。您根本不需要第二个视图控制器。
在您的 XIB 中,创建一个新的顶级 UIWindow 对象。将您的第二个视图放入此窗口中。将窗口连接到视图控制器上的插座。 (我给插座打了电话otherWindow
在我的测试代码中但是overlayWindow
会是一个更好的名字。需要声明出口strong
or retain
.)
在您的视图控制器中,实现以下方法:
- (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;
}];
}
使用它们来呈现和关闭覆盖视图。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)