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