使用UIPresentationFormSheet,为什么我的视图在启动时不移到键盘上方? [英] With UIPresentationFormSheet, why doesn't my view move above the keyboard when it is up?

查看:70
本文介绍了使用UIPresentationFormSheet,为什么我的视图在启动时不移到键盘上方?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

苹果说:

UIModalPresentationFormSheet 呈现的视图的宽度和高度小于屏幕的宽度和高度,并且视图位于屏幕的中心. 如果设备横向放置且键盘可见,则向上调整视图的位置,以使视图保持可见.所有未覆盖的区域均变灰以防止用户与它们进行交互.

UIModalPresentationFormSheet The width and height of the presented view are smaller than those of the screen and the view is centered on the screen. If the device is in a landscape orientation and the keyboard is visible, the position of the view is adjusted upward so that the view remains visible. All uncovered areas are dimmed to prevent the user from interacting with them.

但是,当键盘可见时,我的视图不会向上移动.我基本上想在键盘上方以模态形式显示一个textview,以便用户可以输入文本,然后单击send(在显示的视图上的导航栏按钮中.)

But my view doesn't move up when the keyboard is visible. I basically want to present a textview modally above the keyboard so the user can enter text and then hit send (in a nav bar button on the presented view.)

我的呈现视图是UISplitViewController(不是其子级之一),我呈现的是UINavigationController,其顶部视图控制器基本上是UITextView.可以旋转,但是键盘在两个方向上都重叠了显示的视图.

My presenting view is a UISplitViewController (not one of its children) and I'm presenting UINavigationController who's top view controller is basically a UITextView. Rotation works, but the presented view is overlapped by the keyboard in both orientations.

我发现一些 询问在这种情况下如何调整显示视图的大小,这很好,但是我不想通过手动调整大小来进行假设.演示者或呈现的视图.似乎应该选择一个合适的尺寸(未记录),在键盘显示时自动将其向上移动.

I found some questions asking how to resize the presented view in this case, which is nice, but I don't want to have to make assumptions by resizing manually in the presenter or in the presented view. It seems like it should just pick a decent (undocumented) size just move it up automatically when the keyboard shows.

我的演示代码如下:

MyViewController *vc = [[MyViewController alloc] init];
UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
nav.modalPresentationStyle = UIModalPresentationFormSheet;
[self.splitViewController presentModalViewController:nav animated:YES];

推荐答案

在完成问题时,我意识到我正在viewWillAppear中的UITextView上调用becomeFirstResponder.如果将其更改为viewDidAppear,它将起作用,这很有意义.

As I was finishing up my question, I realized I was calling becomeFirstResponder on my UITextView in viewWillAppear. If you change it to viewDidAppear it will work, which makes sense.

这篇关于使用UIPresentationFormSheet,为什么我的视图在启动时不移到键盘上方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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