title: Autolayout: UIImageView not rotating with device orientation
body: <p>There's probably a dozen SO questions with similar titles, and as far as I can see, I've incorporated the advice from every one of them, with no luck. When I rotate the device from portrait to landscape, I want to change the background image. However, in every experiment I have tried, the UIImageView in landscape remains portrait sized.</p>
  
  <p>I am using Autolayout, configured in IB like so:</p>
  
  <p><a href="https://i.stack.imgur.com/GPMV8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GPMV8.png" alt="autolayout"></a></p>
  
  <p>My view hierarchy is configured like so:</p>
  
  <p><a href="https://i.stack.imgur.com/E7wDp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E7wDp.png" alt="enter image description here"></a></p>
  
  <p>When I rotate the device, I want to rotate everything in UIView <code>viewBackground</code> (the image and all of the buttons). I believe I can manage the button movements through constraints, but need to rotate UIImageView <code>image view background</code> myself. So, I added the following code:</p>
  
  <pre><code>-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id&lt;UIViewControllerTransitionCoordinator&gt;)coordinator
  {
      int scaleFactor = self.traitCollection.displayScale;
      NSString *source = @"drawn";
  
      NSString *orientation;
      if (size.width &gt; size.height)
      {
          orientation = @"Landscape";
      }
      else
      {
          orientation = @"Portrait";
      }
  
      NSString *platform;
      if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
      {
          platform = @"iPad";
      }
      else
      {
          platform = @"iPhone";
      }
  
      NSString *filename = [NSString stringWithFormat:@"%@ %@ %@ %.0fx%.0f.png", source, platform, orientation, size.width * scaleFactor, size.height * scaleFactor];
  // CONFIRMED: we have assembled the correct new image name.
  
     viewBackground.frame = CGRectMake(0, 0, size.width * scaleFactor, size.height * scaleFactor);
      viewBackground.autoresizesSubviews = YES;
      viewBackground.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
      imageViewBackground.autoresizesSubviews = YES;
      imageViewBackground.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
      imageViewBackground.image = [UIImage imageNamed:filename];
  }
  </code></pre>
  
  <p><strong>The problem:</strong> The correct image appears on the screen, but as as mentioned above, it still has the portrait dimensions. I'm certain the image changes as the artwork is significantly different, with elements being stacked horizontally versus vertically. But the new picture is cut off horizontally in landscape mode. </p>
  
  <p>I have tried putting all sorts of wild values into <code>newRect</code>, and none of them make any difference. The image never actually moves, even if I radically change the origin in <code>newRect</code>.  so my current theory is that my changes to the view sizes are being ignored/over written.</p>
  
  <p><strong>The Question:</strong> What am I missing that's preventing the resizing of the image to landscape mode? Is there some other auto sizing aspect I'm not addressing?</p>