가장 쉬운 해결책은 모든 이미지에 너비와 높이 제한에 대한 고정 값을 제공하는 것입니다. 그런 다음 원하는대로 superview에서 spotlightImage를 정렬하고 정지 이미지와 관련하여 원 이미지의 정렬을 정의 할 수 있습니다.
그러나 화면의 너비에 따라 신호등 이미지의 너비를 늘리려면 복잡한 문제입니다. 스토리 보드에서 모든 제약 조건을 정의하려고 조금 노력했지만 적절한 해결책을 제시하지 못했습니다. 예를 들어, 이상적으로 스포트라이트 이미지의 폭에 비례하여 원의 centreX를 정의하는 것이 이상적입니다. y 위치와 비슷합니다. 불행히도 이것은 불가능합니다.
코드 1에는 약간의 제어 권한이 있습니다.다음은 작동 할 해결책입니다. 실제로 spotlightImage의 폭을 다시 계산되기 때문에 그것은 꽤 아니지만, 우리는 당신의 신호등 배경 이미지의 제약뿐만 아니라 제약을 볼 필요가
class ViewController: UIViewController {
lazy var stopLightImageView: UIImageView = {
return UIImageView(image: UIImage(named:"stopLight"))
}()
lazy var circleImageView: UIImageView = {
return UIImageView(image: UIImage(named:"circle"))
}()
override func viewDidLoad() {
super.viewDidLoad()
setupViews()
}
private func setupViews() {
//Values at start. This is used to calculate the proportional values, since you know they produce the correct results.
let stoplightStartWidth: CGFloat = 540
let stoplightStartHeight: CGFloat = 542
let circleStartWidth: CGFloat = 151
let circleStartLeading: CGFloat = 231
let circleStartTop: CGFloat = 52
let screenWidth = UIScreen.mainScreen().bounds.size.width
let stoplightMargin: CGFloat = 20
self.view.addSubview(stopLightImageView)
stopLightImageView.translatesAutoresizingMaskIntoConstraints = false
//stoplightImage constraints
stopLightImageView.leadingAnchor.constraintEqualToAnchor(self.view.leadingAnchor, constant: stoplightMargin).active = true
stopLightImageView.trailingAnchor.constraintEqualToAnchor(self.view.trailingAnchor, constant: -stoplightMargin).active = true
stopLightImageView.centerYAnchor.constraintEqualToAnchor(self.view.centerYAnchor, constant: 0).active = true
stopLightImageView.heightAnchor.constraintEqualToAnchor(stopLightImageView.widthAnchor, multiplier: stoplightStartWidth/stoplightStartHeight).active = true
self.view.addSubview(circleImageView)
circleImageView.translatesAutoresizingMaskIntoConstraints = false
//circle constraints
circleImageView.widthAnchor.constraintEqualToAnchor(stopLightImageView.widthAnchor, multiplier: circleStartWidth/stoplightStartWidth).active = true
circleImageView.heightAnchor.constraintEqualToAnchor(circleImageView.widthAnchor, multiplier: 1).active = true
let stoplightWidth = screenWidth - 2*stoplightMargin
let stoplightHeight = stoplightWidth * stoplightStartHeight/stoplightStartWidth
circleImageView.leadingAnchor.constraintEqualToAnchor(stopLightImageView.leadingAnchor, constant: stoplightWidth*circleStartLeading/stoplightStartWidth).active = true
circleImageView.topAnchor.constraintEqualToAnchor(stopLightImageView.topAnchor, constant: stoplightHeight*circleStartTop/stoplightStartHeight).active = true
}
}

:-) 작동 버튼 3 개를 설정했습니다. 3 개의 단추가보기에 제약 조건이 설정되어있는 것처럼 보입니다. 이러한 제약 조건을 신호등 배경 이미지로 설정하면 해당 단추가 올바른 위치에 유지됩니다. –