1
我試圖通過設置約束來垂直對齊logoImage
水平&但在測試時顯示在(x:0, y:0)
上。 任何想法如何解決這個問題? 感謝嘗試以編程方式實現約束時忽略約束條件
var movieView : UIView?
let logoImage = UIImageView(image: #imageLiteral(resourceName: "my_logo"))
// This function runs in viewWillAppear
internal func setupIntroMovie() {
movieView = UIView(frame: view.frame)
view.addSubview(movieView!)
view.addSubview(logoImage)
let horizontalConstraint = NSLayoutConstraint(item: logoImage,
attribute: .centerX,
relatedBy: .equal,
toItem: view,
attribute: .centerX,
multiplier: 1,
constant: 0)
let verticalConstraint = NSLayoutConstraint(item: logoImage,
attribute: .centerY,
relatedBy: .equal,
toItem: view,
attribute: .centerY,
multiplier: 1,
constant: 0)
view.addConstraints([horizontalConstraint,
verticalConstraint])
updateViewConstraints()
}
術語「錯誤」太含糊。在哪一行,什麼是完整的錯誤? –
什麼是不行的?它是不是像你期望的那樣出現在屏幕上?應用程序崩潰了嗎?日誌中是否有警告? –
@ Mr.Xcoder對不起,我忘了解決題目。它不會給我任何錯誤 – Slowpoke