如何获取当前约束并稍后为UIView设置它们。我这样做了吗?
获取当前限制
// get current constraints
var txtViewConstraints = txtView.constraints()
稍后设置约束
override func viewDidLayoutSubviews() {
if txtViewConstraints.isEmpty == false {
txtView.addConstraints(txtViewConstraints)
}
}
编辑:这是此问题的后续内容:BringSubViewToFront Repositions UIView in AutoLayout
@IBAction func moveTxtView(sender: UIPanGestureRecognizer) {
var translation: CGPoint = sender.translationInView(self.view)
sender.view?.center = CGPointMake(sender.view!.center.x + translation.x, sender.view!.center.y + translation.y)
sender.setTranslation(CGPointMake(0, 0), inView: self.view)
txtViewConstraints = txtView.constraints()
txtViewPosition = CGRect(x: txtView.frame.origin.x, y: txtView.frame.origin.y, width: txtView.frame.size.width, height: txtView.frame.size.height)
}