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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28008775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 04:24:36  来源:igfitidea点击:

How do I get the current x and y position so that I can use GCRectMake?

iosswiftcgrectmake

提问by Cesare

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 位置?

回答by kcome

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