xcode CGAffineTransformMakeTranslation 转换为一个点而不是一个值。
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7768681/
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
CGAffineTransformMakeTranslation translate to a point rather then by a value.
提问by Eric Brotto
My question is simple.
我的问题很简单。
Let us say I use this method
假设我使用这种方法
CGAffineTransformMakeTranslation(5.0f, 0.0f);
which translates the image view 5 pixels to the right. But is there a similar method that does the exact same thing except takes the destination point as an argument rather then the values you want to move the image view by?
将图像视图向右平移 5 个像素。但是有没有一种类似的方法可以做完全相同的事情,除了将目标点作为参数而不是您想要移动图像视图的值?
For example, if I wanted to move an image view to 100.0f, 0.0f what would I use?
例如,如果我想将图像视图移动到 100.0f、0.0f,我会使用什么?
回答by Fernando Cervantes
You can use the following two options:
您可以使用以下两个选项:
imgOne.center = CGPointMake(50, 50);
or
或者
imgOne.frame = CGRectMake(50, 50, imgOne.frame.size.width, imgOne.frame.size.height);
回答by Ole Begemann
If it's the center point you want to move to this coordinate, use:
如果它是您要移动到此坐标的中心点,请使用:
imageView.center = CGPointMake(100.0f, 0.0f);
If it's one of the corner points, subtract/add half the view's frame's width/height to the coordinates. If you need this frequently, it's a good idea to write a small UIView
category that allows you to position a view's corner on a particular coordinate.
如果它是角点之一,则将视图框架的宽度/高度的一半减去/添加到坐标。如果您经常需要这样做,最好编写一个小UIView
类别,允许您将视图的角定位在特定坐标上。