UITextView 旋转自定义 inputView 时出现问题

发布于 2024-11-14 14:09:50 字数 336 浏览 10 评论 0原文

我编写了一个自定义输入视图,旨在用于替换 UITextView 的标准键盘。如果我将自定义 UIView 指定为 UITextViewinputView,则它在纵向和横向模式下都能按预期工作。

当我旋转设备时就会出现问题 - 每当我这样做时,我的自定义 UIView 都会扩展以填充整个屏幕,而不是仅仅覆盖键盘。我没有任何自定义调整大小的代码 - 我实际上只是将 UIView 指定为 UITextView 的 inputView 属性,然后旋转设备。

当我旋转设备时,如何使自定义键盘视图仅占用普通键盘占用的空间?

I've written a custom input view that is meant to be used to replace the standard keyboard for a UITextView. If I assign my custom UIView as my UITextView's inputView, it works as expected in both portrait and landscape mode.

The problem occurs when I rotate the device - whenever I do this, my custom UIView expands to fill the entire screen, instead of just covering up the keyboard. I don't have any custom resizing code anywhere for this - I'm literally just assigning the UIView as the UITextView's inputView property and then rotating the device.

How do I get my custom keyboard view to only occupy the space taken up by the normal keyboard when I rotate the device?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

岁月流歌 2024-11-21 14:09:50

来自苹果文档:

您可以非常灵活地定义输入视图或输入附件视图的大小和内容。尽管这些视图的高度可以是您想要的,但它们应该与系统键盘的宽度相同。如果 UIKit 遇到在其自动调整大小掩码中具有 UIViewAutoresizingFlexibleHeight 值的输入视图,它会更改高度以匹配键盘。

http://developer.apple.com/library/ios/#Documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/InputViews/InputViews.html#//apple_ref/doc/uid/TP40009542-CH12-SW1

From Apple docs:

You have a lot of flexibility in defining the size and content of an input view or input accessory view. Although the height of these views can be what you’d like, they should be the same width as the system keyboard. If UIKit encounters an input view with an UIViewAutoresizingFlexibleHeight value in its autoresizing mask, it changes the height to match the keyboard.

http://developer.apple.com/library/ios/#Documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/InputViews/InputViews.html#//apple_ref/doc/uid/TP40009542-CH12-SW1

夏日浅笑〃 2024-11-21 14:09:50

如果我记得的话,默认情况下,autoresizingMaskUIViewAutoresizingNone 。你的autoresizingMask应该是UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleHeight UIViewAutoresizingFlexibleTopMargin。

The autoresizingMask is UIViewAutoresizingNone by default if I remember. You autoresizingMask should be UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin.

烟花肆意 2024-11-21 14:09:50

我遇到了这个问题。解决这个问题的方法是:

  1. 打开键盘的viewcontroller.m文件

  2. 找到- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 方法

  3. 使其返回 NO。

我的猜测是视图正在进行双重旋转。

I had this problem. The way to fix this is:

  1. Open the viewcontroller .m file of the keyboard

  2. Find the - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation method

  3. Make it return NO.

My guess is that the view was doing a double rotate.

梦过后 2024-11-21 14:09:50

使您的 inputViews autoresizingMask = UIViewAutoresizingNone;
使用 autoresizingMask 的不同值(特定于版本)应该会有所帮助。

以下是我为 iPad 制定的一些细节(可能这会对您有所帮助):

  1. 如果输入视图是选取器视图,则默认情况下会自动调整大小,这意味着
    框架设置为所需的矩形。在 iPad 的不同目标/版本中,执行此操作的方式略有差异:

      所有目标中的

    1. autoresizemask 至少应为 autoresizeflexiblewidth
    2. 如果 iPad3.2 中未启用 autoresizeflexibleheight,则将矩形设置为 默认(初始) 高度
    3. 如果在 iPad4 中设置了 autoresizeflexibleheight,则将矩形设置为不正确的坐标 (x,y),请勿对选取器视图使用 autoresizeflexibleheight 掩码。
  2. 如果 inputview 不是选取器视图,则应关闭其 flexibleheightautoresizemasks

Make your inputViews autoresizingMask = UIViewAutoresizingNone;
Playing with different values of autoresizingMask (version specific) shall help.

Here are some details , which i worked out some time back for iPad (may be this will help you):

  1. If input view is a Picker view, autoresizing happens by default, which means
    the frame is set to required rect. There is a little discrepancy in the way this is done in different Targets/Versions for iPad:

    1. autoresizemask should at least be autoresizeflexiblewidth in all targets.
    2. Rect set to default(initial) height if autoresizeflexibleheight is not enabled in iPad3.2
    3. Rect set to improper coordinates (x,y) if autoresizeflexibleheight is set in iPad4 do not use autoresizeflexibleheight mask for picker view.
  2. If inputview is not a picker view, its autoresizemasks for flexibleheight should be turned off.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文