0
我有一個我已經設置的位置和大小,通過約束的視圖:動畫約束編程夫特3
oV.centerXAnchor.constraint(equalTo: self.mapViewController.view.centerXAnchor).isActive = true
oV.centerYAnchor.constraint(equalTo: self.mapViewController.view.centerYAnchor).isActive = true
oV.widthAnchor.constraint(equalTo: self.mapViewController.view.widthAnchor, constant: -overlaySpacing).isActive = true
oV.heightAnchor.constraint(equalTo: self.mapViewController.view.heightAnchor, constant: -overlaySpacing).isActive = true
然而,我想要的OV(視圖),以開始作爲比這更小的和動畫的在一秒鐘內的最終尺寸。
oV.centerXAnchor.constraint(equalTo: self.mapViewController.view.centerXAnchor).isActive = true
oV.centerYAnchor.constraint(equalTo: self.mapViewController.view.centerYAnchor).isActive = true
oV.widthAnchor.constraint(equalTo: self.mapViewController.view.widthAnchor, constant: -2 * overlaySpacing).isActive = true
oV.heightAnchor.constraint(equalTo: self.mapViewController.view.heightAnchor, constant: -2 * overlaySpacing).isActive = true
我寫的初始約束條件是常量是(-2 * overlaySpacing)。最後的約束是寬度/高度常量只是-overlaySpacing。
我已經以編程方式編寫了所有內容,故事板解決方案無濟於事。
這是我當前的代碼進行動畫處理,但它只是自動顯示爲最終約束:
讓OV = NewOverlayView(的viewController:MVC,框架:CGRect.zero)
self.mapViewController.view.addSubview(oV)
oV.centerXAnchor.constraint(equalTo: self.mapViewController.view.centerXAnchor).isActive = true
oV.centerYAnchor.constraint(equalTo: self.mapViewController.view.centerYAnchor).isActive = true
var widthConstraint = oV.widthAnchor.constraint(equalTo: self.mapViewController.view.widthAnchor, constant: -2 * overlaySpacing)
var heightConstraint = oV.heightAnchor.constraint(equalTo: self.mapViewController.view.heightAnchor, constant: -2 * overlaySpacing)
widthConstraint.isActive = true
heightConstraint.isActive = true
oV.layoutIfNeeded()
widthConstraint.isActive = false
heightConstraint.isActive = false
widthConstraint = oV.widthAnchor.constraint(equalTo: self.mapViewController.view.widthAnchor, constant: -overlaySpacing)
heightConstraint = oV.heightAnchor.constraint(equalTo: self.mapViewController.view.heightAnchor, constant: -overlaySpacing)
widthConstraint.isActive = true
heightConstraint.isActive = true
UIView.animate(withDuration: 1.0) { oV.layoutIfNeeded() }
謝謝!