gpt4 book ai didi

ios - 更改 UIImageView 位置的问题

转载 作者:行者123 更新时间:2023-11-28 06:06:00 25 4
gpt4 key购买 nike

我想在 ios 设备上移动 UIImageView。我可以移动它,但是偏移有问题,因为当我单击图像时,我将 ImageView 中心设置为 anchor 移动点。如何将触摸屏 CGPOint 设置为移动 UIImageView 的 anchor ?

override func touchesBegan( . . . ){
location = touch.location(in : self.view)
. . .
imageView.center = location
. . .
}

override func touchesMoved( . . . ){
location = touch.location(in : self.view)
. . .
imageView.center = location
. . .
}

最佳答案

试试这个:

var offset: CGPoint = CGPoint.zero

override func touchesBegan( . . . ){
offset = touch.location(in: imageView)
offset.x = (imageView.bounds.width / 2) - offset.x
offset.y = (imageView.bounds.height / 2) - offset.y

location = touch.location(in : self.view)
location.x = location.x + offset.x
location.y = location.y + offset.y
. . .
imageView.center = location
. . .
}

override func touchesMoved( . . . ){
location = touch.location(in : self.view)
location.x = location.x + offset.x
location.y = location.y + offset.y
. . .
imageView.center = location
. . .
}

关于ios - 更改 UIImageView 位置的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48203662/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com