3

On my project, the first screen has a full-screen image in the background. I would like to painlessly switch images depending on device and orientation. I have a storyboard scene with a full-view UIImage.

I already know how to use the Asset library to specify a different image for iPad / iPhone and 1x 2x 3x. It will automatically select the best image.

Is there a way to do the same thing for an orientation change? I have a different image that I would like to display when the iPad is in landscape.

Sean Clark Hess
  • 15,859
  • 12
  • 52
  • 100
  • You can specify image based on size class, but unfortunately landscape iPad is not a different size class! – matt Feb 18 '16 at 22:50
  • I'm not sure you can use the image assets specifically for different orientations, but you can listen to an orientation change, and when orientation changes, you can pick the correct image asset. like change from asset "picture" to "picture-landscape" or something. – David Feb 18 '16 at 22:50
  • 1
    Bummer you can't do it with Size classes! It's so close. – Sean Clark Hess Feb 18 '16 at 23:07
  • This hack worked for me: http://stackoverflow.com/questions/26633172/sizing-class-for-ipad-portrait-and-landscape-modes/28268200#28268200 – Sean Clark Hess Feb 18 '16 at 23:52

1 Answers1

0

Don't know if you can do it directly from Image Assets. One way would be to do something like that:

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    if UIDevice.currentDevice().orientation.isLandscape.boolValue && UIDevice.currentDevice().userInterfaceIdiom == .Pad {
        // Load First Image
    } else {
        // Load second Image
    }
}
Guy Daher
  • 5,526
  • 5
  • 42
  • 67