1

I have the following code in the viewWillAppear function:

CAGradientLayer *bgLayer = [BackgroundLayer yellowGradient];
[bgLayer setBounds:self.view.bounds];
[self.view.layer insertSublayer:bgLayer atIndex:0];

It works perfectly in portrait orientation. However, when the device goes into landscape mode, it produces a white (or default color) background down the side. I have seen other examples of WHY this occurs, but nothing on how to fix it.

What I’m seeing happening is the 1024 resolution on landscape (iPad) dropping to 1004, and I think it’s adjusting it to 0,20 on the x, y.

Has anyone else run into this issue and found how to fix it?

jamesplease
  • 12,547
  • 6
  • 47
  • 73
Jeremy
  • 366
  • 5
  • 15

1 Answers1

1

It’s because when you turn the screen sideways, your view, which has a certain background color, does not turn sideways. The view remains in portrait. So you have this portrait-oriented colored view that’s going from the new “top” of the iPad to way below off screen, and on the right side, the view isn’t wide enough to reach, so you just see the app’s default (white) background color.

You can:

  • apply a CGAffineTransformMakeRotation rotation to your self.view 90º, so that it now displays properly in your now-landscape application,
  • make your view big enough to cover the entire device, in both landscape and portrait,
  • make a view with the proper landscape dimensions, and add it when the iPad rotates, or
  • disable those allowed interface orientations in your Xcode main project file.

Link to CGAffineTransformRotation Demo Code on SO: How to use CGAffineTransformMakeRotation?

Community
  • 1
  • 1
Albert Renshaw
  • 17,282
  • 18
  • 107
  • 195
  • Oh....I have never used the CGTransform function. But I don't know why I didn't think of the other solution. der. Let me give that a go and I'll see if it works. – Jeremy Jan 14 '13 at 09:24
  • Didn't work...either I'm doing something wrong (likely) or it's wigging still with the portrait vs landscape.I really thought that putting a view into the storyboard then adjusting it like you said would work. The view is perfect the color is still messed up. – Jeremy Jan 14 '13 at 23:23
  • 1
    Got it working Thanks Albert! I read an article from another developer /designer which stated. It's unwise to blur the layers of developement. If its design let your designers use the tools that have been designed for it. Don't re-create the effect in code as it may not be as helpful.... – Jeremy Jan 15 '13 at 21:29