arsena arsena - 23 days ago 7
iOS Question

Keyboard appears in wrong orientation in ios

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.

enter image description here

But if I dismiss the keyboard, rotate the device left or right and then open the popup, keyboard still opens in portrait mode.

enter image description here

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.

Any ideas what to do?

Answer

Ok, fixed it, my fault I guess.

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.

So I changed this:

public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
    {
        if (someStatement)
        {
            return UIInterfaceOrientationMask.AllButUpsideDown;
        }
        return UIInterfaceOrientationMask.Portrait;
    }

To this:

    public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
    {
        return UIInterfaceOrientationMask.AllButUpsideDown;
    }

And now only ShouldAutoRotate decides whether it rotation should happen or not.

To some up it should look like this:

public override bool ShouldAutorotate()
    {
        if (someStatement)
        {
            return true;
        }
        return false;
    }

    public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
    {
        return UIInterfaceOrientationMask.AllButUpsideDown;
    }
Comments