键盘在iOS中的显示方向错误 [英] Keyboard appears in wrong orientation in ios

查看:182
本文介绍了键盘在iOS中的显示方向错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一个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.

似乎Keyboard和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中的显示方向错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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