0
我增加了一個的UIButton,並通過故事板的的UIView,並創造了IBOutlets如何更改故事板中添加的UIView的中心?
@IBOutlet weak var popUpView: UIView!
@IBOutlet weak var nextButton: UIButton!
當我試圖改變center
或frame
,這是行不通的:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
popUpView.center = CGPoint(x:50,y:50)
nexButton.frame = CGRect(x: 0, y: 50, width: 100, height: 100)
}
但這個工程:
nextButton.layer.cornerRadius = 0.2 * nextButton.bounds.size.width
爲什麼你需要改變中心?將該視圖從最初的配置放置在所需的位置! – Lion
您使用的是自動佈局嗎?如果是,那麼你必須創建你想要動態改變的約束的出口。 –
嘗試在viwDidAppear()方法的結尾大括號之前調用layoutIfNeeded()! – Ariel