I have this scene of a neon cassette as you see. In the interface builder I have created 3 UIImageViews, one for the background of the cassette and 2 for the left and right spindles. The idea is that these spindles spin backwards or forwards depending on the state (rewind, ffw or play). I can do this fine in the case that I run this solely on, say, an iPhone 8. However, when I decide I want to run this on an iPhone 11 Pro, the following happens:
No matter what bizarre mixture of constraints I attempt to concoct, I am unable to have the spindles follow their correct position/size across devices. I will have to spend some time finding and reading guides on the beast that is Auto Layout, but until that mountain is climbed, I'd appreciate any help!
EDIT:
Here is a programmatic, so more descriptive, version of what I have so far:
override func viewDidLoad() {
super.viewDidLoad()
// Code to position/size cassette
let cassette = UIImageView(image: UIImage(named: "cassette"))
cassette.translatesAutoresizingMaskIntoConstraints = false
cassette.contentMode = .scaleAspectFit
view.addSubview(cassette)
view.safeAreaLayoutGuide.bottomAnchor.constraint(equalTo: cassette.bottomAnchor, constant: 44).isActive = true
view.safeAreaLayoutGuide.trailingAnchor.constraint(equalTo: cassette.trailingAnchor, constant: 20).isActive = true
cassette.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 20).isActive = true
cassette.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 44).isActive = true
// Code to position/size spindles
let spindleLeft = UIImageView(image: UIImage(named: "spindle"))
spindleLeft.translatesAutoresizingMaskIntoConstraints = false
spindleLeft.widthAnchor.constraint(equalToConstant: 74).isActive = true
spindleLeft.heightAnchor.constraint(equalToConstant: 74).isActive = true
cassette.addSubview(spindleLeft)
spindleLeft.centerXAnchor.constraint(equalTo: cassette.centerXAnchor, constant: -130.0).isActive = true
spindleLeft.centerYAnchor.constraint(equalTo: cassette.centerYAnchor, constant: -14.0).isActive = true
}
I'm currently stuck trying to figure out if there's some way to use the aspectRatio of the device and what UIImageView Content Mode (Aspect Fit, Aspect Fill) I should use. Perhaps I've dug too deep a whole and there's a far simpler way to deal with this that I'm not seeing...