0
当我使用'UIPanGestureRecognizer'移动'UIImageView'对象时,我注意到'center'属性没有改变。为什么是这样,我做错了什么?以下是代码:为什么用UIPanGestureRecognizer(Swift)平移UIImageView.center不会改变?
func handlePanning1(recognizer: UIPanGestureRecognizer)
{
var index: Int = recognizer.view!.tag - 1 // index in the arrays for this piece
var newTranslation: CGPoint = recognizer.translationInView(pieces[index])
recognizer.view?.transform = CGAffineTransformMakeTranslation(lastTranslations[index].x + newTranslation.x, lastTranslations[index].y + newTranslation.y)
// THIS ALWAYS PRINTS OUT THE SAME WHILE I'M PANNING
// AND IF I PAN MULTIPLE TIMES IN DIFFERENT DIRECTIONS (AKA IT NEVER CHANGES)
print(Int(pieces[index].center.x))
print("\n")
if recognizer.state == UIGestureRecognizerState.Ended {
lastTranslations[index].x += newTranslation.x
lastTranslations[index].y += newTranslation.y
}
}
哦,好的,这很有道理。因此,在使用“UIPanGestureRecognizer”进行平移时,最好是应用转换还是实际移动它(通过更改“中心”)? – 2014-10-31 19:20:55
取决于你想完成什么。我还没有考虑哪个更有效率,我会假设实际上移动它,但这只是一个假设。如果您依靠其中心来更新位置,请继续并更新中心。 – 2014-10-31 19:27:42