2

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?

Community
  • 1
  • 1
arsena
  • 1,935
  • 19
  • 36
  • Can you display the code you handle your orientation with, potentially with some screenshots if created using IB ? – CodingNagger Nov 07 '16 at 13:54
  • @IamNguele I can, but code is in Xamarin. I Usually avoid putting Xamarin code in questions where I expect native developers to answer if there's no absolute necessity. Unfortunately, It becomes less likely that they will answer. :( – arsena Nov 07 '16 at 14:19
  • 1
    http://stackoverflow.com/questions/40318488/uialertcontroller-addtextfield-orientation-issue-from-ios10-on-ipad#comment68002435_40318488 - may be this can help - read the comments – Annie Gupta Nov 07 '16 at 14:59
  • 1
    I have a client that has almost half their users (~3k effected) with this issue on iPads after upgrading to iOS 10.1.1 (last week). Apple response so far is: Power cycle the device and try again... ;-( and wait for iOS 10.2... They have a couple of devs working on a hack to reset the keyboard manually but it will not be Store acceptable... – SushiHangover Nov 07 '16 at 15:32
  • @SushiHangover thanks for the response, can you link any official sources regarding the issue? if there are any topics on apple forums or anything – arsena Nov 07 '16 at 15:48
  • BTW, I'm testing on 10.1.1 and 10.0.1. Get same results on both. don't have older ios versions to test. – arsena Nov 07 '16 at 15:50
  • 1
    @arsena I personally do not have any public links. I know that their bugreporter issue is marked as a dup and of course the dup is not viewable... They got contacted due to the visibility of their app in the medical market... It is a strange bug as getting it to reproduce in order to debug appears to be hardware/firmware/iOS version & App software dependent... but this is not really a new bug, as it surfaced in ios8(?) and was patched and it regressed(?) two versions later... that is why the client is hacking a patch for it, it can be worked around somehow using private apis. – SushiHangover Nov 07 '16 at 16:04
  • @arsena I would recommend using bugreporter and see if you get a response... – SushiHangover Nov 07 '16 at 16:08
  • thanks, you helped a lot. I'll try it. – arsena Nov 07 '16 at 16:10

4 Answers4

2

I got exactly the same wrong keyboard orientation in some of my view controllers recently after I dropped support for iOS 8 and bumped up the deployment target to iOS 9. It turns out that one of my former colleagues used a solution here to solve an old problem when the base SDK was iOS 9 (we're now in 10, and 11 when coding from Xcode 9 beta). That solution (basically override UIAlertController's supportedInterfaceOrientations to only allow portrait) would force present the keyboard in portrait with newer SDK + deployment target even though the app window and the alert itself are in landscape.

Removing that override solved the problem and I don't see any issue with alert over alert.

CodeBrew
  • 6,457
  • 2
  • 43
  • 48
0

Try by adding below code to your viewcontroller's viewDidAppear method

 - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
        [[UIDevice currentDevice] setValue:@(UIDeviceOrientationLandscapeLeft) forKey:@"orientation"];
        [[UIDevice currentDevice] setValue:@(self.interfaceOrientation) forKey:@"orientation"];

    }
Satish Mavani
  • 4,897
  • 2
  • 20
  • 30
0

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;
    }
arsena
  • 1,935
  • 19
  • 36
-1

Create subclass of UIAlertController

MyAlertController.h //header file
@interface MyAlertController : UIAlertController

@end

MyAlertController.m
@implementation MyAlertController 

- (BOOL)shouldAutorotate
{
  return NO;
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
  [super supportedInterfaceOrientations];    
  return UIInterfaceOrientationMaskLandscape;
}
@end
  • You should never try to override methods using an extension. If you want to override, you need a subclass, otherwise the behavior will be undefined. – Sulthan Nov 25 '18 at 15:37
  • I agree with you, I change it to subclass the UIAlertController, Thanks for your comment. – Oriel Dayanim Nov 27 '18 at 09:42