title: Can't get background gradient to fill entire screen upon rotation
body: <p>I have a background gradient that draws nicely when the screen is initially rendered in portrait mode. However, when the device is rotated to landscape mode, the right 40% of the screen is black (i.e. the background is not drawn on the part of the screen that wasn't previously drawn). I don't know how to get the background to redraw to fill the entire screen.</p>
  
  <p>Can anyone tell me what I am doing wrong? Thanks!</p>
  
  <p>Here is how it looks when initially drawn.
  <img src="https://i.stack.imgur.com/tTZI2.png" alt="enter image description here"></p>
  
  <p>And here is now it looks when I rotate it:</p>
  
  <p><img src="https://i.stack.imgur.com/4OSmQ.png" alt="enter image description here"></p>
  
  <p>Here is the code for my background gradient class:</p>
  
  <pre><code>#import "BackgroundGradient.h"
  
  @interface BackgroundGradient()
  @property (strong, nonatomic) UIView *view;
  @end
  
  @implementation BackgroundGradient
  
  - (id) initWithView:(UIView *) view
  {
      if (!_view)
          _view = view;
  
      return self;
  }
  
  - (void) makeGradient
  {
      UIColor *darkOp = [UIColor colorWithRed:(193.0 / 255.0) green:(215.0 / 255.0) blue:(46.0 / 255.0) alpha: 1];
      UIColor *lightOp = [UIColor colorWithRed:(222.0 / 255.0) green:(233.0 / 255.0) blue:(143.0 / 255.0) alpha: 1];
  
      // Create the gradient
      CAGradientLayer *gradient = [CAGradientLayer layer];
  
      // Set colors
      gradient.colors = [NSArray arrayWithObjects:
                         (id)darkOp.CGColor,
                         (id)lightOp.CGColor,
                         (id)darkOp.CGColor,
                         nil];
  
      // Update the start and end points
      gradient.startPoint = CGPointMake(0.5, 0.0);
      gradient.endPoint = CGPointMake(0.5, 1.0);
  
      // Set bounds
      gradient.frame = self.view.bounds;
  
      // Add the gradient to the view
      [self.view.layer insertSublayer:gradient atIndex:0];
  
      gradient.locations = [NSArray arrayWithObjects:
                            [NSNumber numberWithFloat:0.0f],
                            [NSNumber numberWithFloat:0.7],
                            [NSNumber numberWithFloat:0.9],
                            nil];
  
  }
  
  @end
  </code></pre>
  
  <p>And finally, here is how I instantiate the background object:</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
  
      self.background = [[BackgroundGradient alloc] initWithView:self.view];
      [self.background makeGradient];
  
  }
  </code></pre>
  
  <p>EDIT: I've added the following code and included updates to the start and end points (above):</p>
  
  <pre><code>- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
  {
      [self.background makeGradient];
  }
  </code></pre>
  
  <p>I'm almost there, but now, I get this. Notice how there is still a vertical line. It looks to me like the new background is getting drawn <em>behing</em> the previous background such that the previous background is still there and is blocking the new background. This is particularly noticeable as the animation from portrait to landscape is occurring.</p>
  
  <p><img src="https://i.stack.imgur.com/9UU9U.png" alt="enter image description here"></p>