gpt4 book ai didi

objective-c - 对 UIBezierPath 应用缩放和平移转换

转载 作者:搜寻专家 更新时间:2023-10-30 19:41:42 25 4
gpt4 key购买 nike

我有一个 UIBezierPath,我想:

  • 移动到UIView上的任意坐标
  • 变大或变小

我正在根据预定义坐标列表绘制 UIBezierPath。我实现了这段代码:

CGAffineTransform move = CGAffineTransformMakeTranslation(0, 0);

CGAffineTransform moveAndScale = CGAffineTransformScale(move, 1.0f, 1.0f);
[shape applyTransform:moveAndScale];

我也试过缩放然后移动形状,这似乎没什么区别。

使用这段代码:

[shape moveToPoint:CGPointMake(0, 0)];  

我从 (0, 0) 开始绘制形状,但实际情况是这样的。我假设这是因为从 0、0 到列表中的下一个点绘制了一条线。

enter image description here

当我将移动转换设置为 (0, 0) 时,这就是它绘制的位置。此处,moveToPoint 设置为列表中的第一个坐标对。如您所见,它不在 0, 0。

enter image description here

最后,无论我告诉形状移动到哪里,增加 1.0f 都会将形状完全移出屏幕。

谁能帮我理解为什么形状没有绘制在 0, 0 处,以及为什么当我缩放它时它会移出屏幕。

最佳答案

(根据 OP 在上面评论中的要求)

我在这方面可能是错的,但这段代码不是吗

CGAffineTransformMakeTranslation(0, 0);

只是说某些东西应该沿 x 轴移动 0 个像素,沿 y 轴移动 0 个像素? ( reference ) 它实际上不会将任何内容移动到 origo (0, 0),就像您正在尝试做的那样。

此外,您似乎对如何正确使用 moveToPoint: 有一点误解。将其视为移动光标的一种方式,但实际上并没有绘制任何东西。这只是一种表达“我想在此时开始绘画”的方式。绘图本身可以通过其他方法执行。如果你想,例如画一个边长为 L 的正方形,然后你可以这样做......

// 'shape' is a UIBezierPath
NSInteger L = 100;
CGPoint origin = CGPointMake(50, 50);
[shape moveToPoint:origin]; // Initial point to draw from
[shape addLineToPoint:CGPointMake(origin.x+L, origin.y)]; // Draw from origin to the right
[shape addLineToPoint:CGPointMake(origin.x+L, origin.y+L)]; // Draw a vertical line
[shape addLineToPoint:CGPointMake(origin.x, origin.y+L)]; // Draw bottom line
[shape addLineToPoint:origin]; // Draw vertical line back to origin

请注意,这段代码根本没有经过测试,但它应该让您了解如何使用 moveToPoint:addLineToPoint:

关于objective-c - 对 UIBezierPath 应用缩放和平移转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16158104/

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