UITextView 旋转自定义 inputView 时出现问题
我编写了一个自定义输入视图,旨在用于替换 UITextView
的标准键盘。如果我将自定义 UIView
指定为 UITextView
的 inputView
,则它在纵向和横向模式下都能按预期工作。
当我旋转设备时就会出现问题 - 每当我这样做时,我的自定义 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
来自苹果文档:
http://developer.apple.com/library/ios/#Documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/InputViews/InputViews.html#//apple_ref/doc/uid/TP40009542-CH12-SW1
From Apple docs:
http://developer.apple.com/library/ios/#Documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/InputViews/InputViews.html#//apple_ref/doc/uid/TP40009542-CH12-SW1
如果我记得的话,默认情况下,
autoresizingMask
是UIViewAutoresizingNone
。你的autoresizingMask应该是UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleHeight UIViewAutoresizingFlexibleTopMargin。The
autoresizingMask
isUIViewAutoresizingNone
by default if I remember. YouautoresizingMask
should beUIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin
.我遇到了这个问题。解决这个问题的方法是:
打开键盘的viewcontroller.m文件
找到
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
方法使其返回 NO。
我的猜测是视图正在进行双重旋转。
I had this problem. The way to fix this is:
Open the viewcontroller .m file of the keyboard
Find the
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
methodMake it return NO.
My guess is that the view was doing a double rotate.
使您的 inputViews autoresizingMask = UIViewAutoresizingNone;
使用 autoresizingMask 的不同值(特定于版本)应该会有所帮助。
以下是我为 iPad 制定的一些细节(可能这会对您有所帮助):
框架设置为所需的矩形。在 iPad 的不同目标/版本中,执行此操作的方式略有差异:
所有目标中的- 如果 iPad3.2 中未启用
- 如果在 iPad4 中设置了
autoresizemask
至少应为autoresizeflexiblewidth
。autoresizeflexibleheight
,则将矩形设置为默认(初始)
高度autoresizeflexibleheight
,则将矩形设置为不正确的坐标 (x,y),请勿对选取器视图使用autoresizeflexibleheight
掩码。inputview
不是选取器视图,则应关闭其flexibleheight
的autoresizemasks
。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):
the frame is set to required rect. There is a little discrepancy in the way this is done in different Targets/Versions for iPad:
autoresizemask
should at least beautoresizeflexiblewidth
in all targets.default(initial)
height ifautoresizeflexibleheight
is not enabled in iPad3.2autoresizeflexibleheight
is set in iPad4 do not useautoresizeflexibleheight
mask for picker view.inputview
is not a picker view, itsautoresizemasks
forflexibleheight
should be turned off.