gpt4 book ai didi

iphone - 缩放和更改 anchor

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

我尝试放大我在 UIImageView 中单击图像女巫的区域。我使用 CGAffineTransformMakeScale 来制作比例尺,我用点击点坐标改变了 imageView.layer.anchorPoint比例正常,但图像不再居中,我想我在 anchorPoint 坐标上错了,我发现很多文章都在讨论它,但它太复杂了

请帮忙!

代码:

-(void)gestureTapEvent:(UITapGestureRecognizer *)gesture {
NSLog(@"doubleclic");

CGPoint touchPoint = [gesture locationInView:gesture.view];
NSLog(@"Position of touch: %.3f, %.3f", touchPoint.x, touchPoint.y);

float newX = touchPoint.x/imageView.frame.size.width;
float newY = touchPoint.x/imageView.frame.size.height;


imageView.transform = CGAffineTransformMakeScale(1.5, 1.5);
imageView.layer.anchorPoint = CGPointMake(newY, newX);
}

最佳答案

图层的内容相对于 anchor 自行绘制。实际上层的anchorPointposition(位置大致对应 View 的center)在两个不同的地方是完全相同的点坐标系: anchor 在层的单位坐标空间中,位置在superlayers坐标空间中。我对这一切有一个非常详细的解释 in this article over at the iDeveloper blog .

简短的解决方案:在设置 anchor 后设置图层的位置。由于进行了转换,因此无法设置框架(有关更多信息,请参阅框架属性的文档)。

另一种解决方案(如果您对位置 anchor 舞蹈感到恼火)是仅使用变换。如果是那种情况,您将连接翻译、缩放和翻译以获得最终转换。我写过基本相同的内容,但在 this article 中进行轮换。 .只需用比例代替旋转 :D

关于iphone - 缩放和更改 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18698092/

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