Orientation issue while presenting Modal ViewController

Posted by Jacky Boy on Stack Overflow See other posts from Stack Overflow or by Jacky Boy
Published on 2014-05-29T15:17:02Z Indexed on 2014/05/29 15:26 UTC
Read the original article Hit count: 244

Current scenario:

Right now I am showing a UIViewController using a segue with the style Modal and presentation Sheet. This Modal gets its superview bounds change, in order to have the dimensions I want, like this:

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    self.view.superview.bounds = WHBoundsRect;
}

The only allowed orientations are UIInterfaceOrientationLandscapeLeft and UIInterfaceOrientationLandscapeRight. Since the Modal has some TextFields and the keyboard would be over the Modal itself, I am changing its center so it moves a bit to the top.

The problem:

What I am noticing right now, is that I am unable to work with the Y coordinate. In order for it move vertically (remember it's on landscape) I need to work with the X. The problem is that when it's UIInterfaceOrientationLandscapeLeft I need to come with a negative X. And when it's UIInterfaceOrientationLandscapeRight I need to come with a positive X. So it seems that the X/Y Coordinate System is "glued" to the top left corner while in Portrait and when an orientation occurs, it's still there:

enter image description here

What I have done

So I have something like this:

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
NSInteger newX = 0.0f;

if (orientation == UIInterfaceOrientationLandscapeLeft)
{
  // Logic for calculating the negative X.
}
else
{
  // Logic for calculating the positive X.
}

It works exactly like I want, but it seems a very fragile implementation. Am I missing something? Is this the expected behaviour?

© Stack Overflow or respective owner

Related posts about ios

Related posts about uiviewcontroller