使用CGAffineTransform缩放并设置锚点 [英] Scale with CGAffineTransform and set the anchor

查看:1438
本文介绍了使用CGAffineTransform缩放并设置锚点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我理解正确缩放 UIView 并使用 CGAffineTransform 将转换锚定到其中心。

If I understand correctly scaling a UIView with CGAffineTransform anchors the transformation to its center.

特别是:

self.frame = CGRectMake(0,0,100,100);
self.transform = CGAffineTransformMakeScale(2, 2);
NSLog(@"%f;%f;%f;%f", self.frame.origin.x, self.frame.origin.y, self.frame.size.width, self.frame.size.height); 

打印:

-50;-50;200;200

如何创建CGAffineTransform比例使用特定的锚点(比如0; 0)?

How do you create a CGAffineTransform scale that uses a specific anchor point (say 0;0)?

推荐答案

(a)

缩放然后翻译?

类似于:

CGAffineTransform t = CGAffineTransformMakeScale(2, 2);
t = CGAffineTransformTranslate(t, width/2, height/2);
self.transform = t;

(b)

设置锚点点(这可能是你真正想要的)

Set the anchor point (which is probably what you want really)

[self layer].anchorPoint = CGPointMake(0.0f, 0.0f);
self.transform = CGAffineTransformMakeScale(2, 2);

(c)

设置中心再次确保它在同一个地方?

Set the center again to make sure it's in the same place?

CGPoint center = self.center;
self.transform = CGAffineTransformMakeScale(2, 2);
self.center = center;

这篇关于使用CGAffineTransform缩放并设置锚点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆