Ios 目标C到X和Y的变换
我一直在研究CGAffineTransforms,想知道是否有一种方法可以在x,y坐标上进行查看和放大。我用函数缩小了缩放部分:Ios 目标C到X和Y的变换,ios,objective-c,cgaffinetransform,Ios,Objective C,Cgaffinetransform,我一直在研究CGAffineTransforms,想知道是否有一种方法可以在x,y坐标上进行查看和放大。我用函数缩小了缩放部分: CGAffineTransformMakeScale(4.00 ,4.00); 但是,我不确定如何将缩放与可能的x,y坐标联系起来。有人做过这样的事吗?我在使用这些函数时可能不正确吗 -(void)buttonSelected:(id)sender { UIButton *b = sender;
CGAffineTransformMakeScale(4.00 ,4.00);
但是,我不确定如何将缩放与可能的x,y坐标联系起来。有人做过这样的事吗?我在使用这些函数时可能不正确吗
-(void)buttonSelected:(id)sender
{
UIButton *b = sender;
CGPoint location = b.frame.origin;
[UIView animateWithDuration:1.3f delay:0.0f options:UIViewAnimationCurveEaseIn animations:^{
CGAffineTransform totalTransform =
CGAffineTransformMakeTranslation(-location.x , -location.y );
totalTransform = CGAffineTransformScale(totalTransform, 4.0f, 4.0f);
totalTransform = CGAffineTransformTranslate(totalTransform, location.x , location.y );
[self.view setTransform:totalTransform];
}completion:^(BOOL finished) {
}];
}
您可以构造执行以下三个步骤的变换:
- 将要缩放的点移动到层的中心李>
- 规模李>
- 向后移动对象,使原始中心回到中心
// to use a point that is (109, 63) from the centre as the point to scale around
CGAffineTransform totalTransform =
CGAffineTransformMakeTranslation(-109.0f, -63.0f);
totalTransform = CGAffineTransformScale(totalTransform, 4.0f, 4.0f);
totalTransform = CGAffineTransformTranslate(totalTransform, 109.0f, 63.0f);
或者,可以更简单地调整
视图.layer
。第二个想法的关键在于,当你第一次调整锚点时,你会得到一个立即的转换,因为所有其他定位都是在中心位置。太好了,我会尝试一下这个想法,谢谢你的快速响应!所以我一直在尝试这个,但运气不好。我正在做的是尝试放大视图上的一组随机图像,但我始终无法看到正确的坐标。我将在上面提供一些代码。我将编写一个测试项目来检查它,但基于您添加的源代码:偏移量位于视图的空间中,相对于视图的中心。因此,如果您想从左上角开始缩放,那么您的位置将是CGPointMake(-self.frame.size.width*0.5f,-self.frame.size.height*0.5f)
。这有什么改进吗?非常感谢你的见解。有了上面的评论,我就能够根据视图中心在脑海中对变换进行排序。非常感谢!