问题描述
我在支持横向和纵向方向的应用程序中有一个 viewcontroller
.
I have one viewcontroller
in application that supports landscape and portrait orientations.
单击按钮时,会出现一个弹出窗口,我应该在其中输入名称.在纵向模式下一切正常.
On a button click, a popup appears where I should enter the name. everything works as it should on portrait mode.
但是如果我关闭键盘,向左或向右旋转设备然后打开弹出窗口,键盘仍然以纵向模式打开.
But if I dismiss the keyboard, rotate the device left or right and then open the popup, keyboard still opens in portrait mode.
我在 viewcontroller
中 shouldAutorotate
返回 true 并且 supportedInterfaceOrientations
返回 AllButUpsideDown
,所以旋转会自动发生.
I've shouldAutorotate
returning true and supportedInterfaceOrientations
returning AllButUpsideDown
in viewcontroller
, so rotation happens automatically.
I tried this and this options but none of them work.
知道该怎么做吗?
推荐答案
好的,修复了,我猜是我的错.
Ok, fixed it, my fault I guess.
似乎键盘和 UIViewController 分别调用 supportedInterfaceOrientations
并根据其返回值进行旋转.我在那里有一个 if-else
语句,并且仅在某些情况下返回 AllButUpsideDown
.当键盘检查是否应该旋转方法时返回Portrait,而viewcontroller
的值为AllButUpsideDown
.
It seems Keyboard and UIViewController call supportedInterfaceOrientations
separately and rotate based on its return value. I had an if-else
statement in there and was returning AllButUpsideDown
only in some cases. When keyboard checked whether it was supposed to rotate method returned Portrait
, and for viewcontroller
value was AllButUpsideDown
.
所以我改变了这个:
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
if (someStatement)
{
return UIInterfaceOrientationMask.AllButUpsideDown;
}
return UIInterfaceOrientationMask.Portrait;
}
为此:
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
return UIInterfaceOrientationMask.AllButUpsideDown;
}
现在只有 ShouldAutoRotate
决定是否应该旋转.
And now only ShouldAutoRotate
decides whether it rotation should happen or not.
有些人应该是这样的:
public override bool ShouldAutorotate()
{
if (someStatement)
{
return true;
}
return false;
}
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
return UIInterfaceOrientationMask.AllButUpsideDown;
}
这篇关于键盘在ios中出现错误的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!