bar*_*oon 1 iphone objective-c uiviewcontroller modalviewcontroller
我有一个模态视图控制器,UITextView成为第一个响应者,键盘显示.
加载此屏幕后,用户可以在提交之前对其输入进行分类.这通过顶部呈现的另一个模态视图控制器发生.
当呈现第二个键盘时,键盘被解除,用户选择,然后当初始UITextView再次成为第一响应者时再次出现.
如何在不解除键盘的情况下呈现第二个模态视图控制器?
编辑:我已经实现了UITextViewDelegate的一部分,我仍然没有得到所需的结果.
- (BOOL)textViewShouldEndEditing:(UITextView *)textView {
return NO;
}
Run Code Online (Sandbox Code Playgroud)
你不能这样做presentModalViewController:animated:.你必须将你的模态视图放在一个单独的UIWindow中,将第二个UIWindow的windowLevel设置为高(如UIWindowLevelStatusBar),并自己在屏幕上和屏幕上设置动画.您根本不需要第二个视图控制器.
在您的XIB中,创建一个新的顶级UIWindow对象.将第二个视图放入此窗口.将窗口连接到视图控制器上的插座.(我otherWindow在我的测试代码中调用了插座但是overlayWindow名字更好.需要声明插座strong或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;
}];
}
Run Code Online (Sandbox Code Playgroud)
使用这些来显示和关闭叠加视图.
| 归档时间: |
|
| 查看次数: |
1489 次 |
| 最近记录: |