【发布时间】:2015-05-24 03:40:22
【问题描述】:
我的viewController 中有一个UIImage,我正在使用UIPanGesture。我目前正在根据 RayWenderlich 教程使用以下代码来移动它。
@IBAction func panImage(sender: UIPanGestureRecognizer) {
let translation = sender.translationInView(self.view)
if let view = sender.view {
view.center = CGPoint(x:view.center.x + translation.x,
y:view.center.y + translation.y)
exitButton1.center = CGPoint(x:exitButton1.center.x + translation.x, y:exitButton1.center.y + translation.y)
}
sender.setTranslation(CGPointZero, inView: self.view)
}
我正在为这个应用程序使用auto layout,并被告知应该将UIImage 与autoLayoutConstraints 一起移动。我更改为以下代码来移动image,但是,图像现在在屏幕上跳跃。
let translation = sender.translationInView(self.view)
image1ConstraintX.constant = image1ConstraintX.constant + translation.x
image1ConstraintY.constant = image1ConstraintY.constant + translation.y
有没有更好的方法来使用constraints 移动image?可以使用第一种方法,然后根据最终位置更新constraints吗?如果正确执行,移动image 的第二种方法会如何?
【问题讨论】:
标签: ios swift uiimage autolayout constraints