如何获取当前的x和y位置以便我可以使用GCRectMake?

时间:2021-10-26 20:36:59

I have this code inside an animation:

我在动画中有这个代码:

image.frame = CGRectMake(x: x, y: y, width, height)

I need to get the x and y coordinates of an image. I found this Objective-C code:

我需要获取图像的x和y坐标。我发现了这个Objective-C代码:

CGPoint origin = imageView.frame.origin;

Once I find the x and y position of the image, I will need to transform it. I will use something like:

一旦找到图像的x和y位置,我将需要对其进行转换。我将使用类似的东西:

image.frame = CGRectMake(x-50, y-50, width+500, height+500)

...so that I can move the image around the screen. How do I find the original x and y positions?

...这样我就可以在屏幕上移动图像了。如何找到原始的x和y位置?

1 个解决方案

#1


42  

Do you mean you want this?

你是说你想要这个吗?

var frm: CGRect = imageView.frame
frm.origin.x = frm.origin.x - 50
frm.origin.y = frm.origin.y - 50
frm.size.width = frm.size.width + 500
frm.size.height = frm.size.height + 500
imageView.frame = frm

#1


42  

Do you mean you want this?

你是说你想要这个吗?

var frm: CGRect = imageView.frame
frm.origin.x = frm.origin.x - 50
frm.origin.y = frm.origin.y - 50
frm.size.width = frm.size.width + 500
frm.size.height = frm.size.height + 500
imageView.frame = frm