我想模拟对视图进行“放大”的效果。较大的视图将作为子视图添加到较小视图的父视图中,并且较大的视图应该看起来像是从较小的视图中放大出来。给定较小视图的矩形fromRect
和放大后较大视图的最终框架finalRect
,应该使用什么样的变换?
我想方法签名应该像下面这样,其中view
是父视图。我写了这个来帮助自己,但还没有弄清楚。
-(CGAffineTransform) translatedAndScaledTransformUsingViewRect:(CGRect)viewRect fromRect:(CGRect)fromRect inView:(UIView*) view
{
//calculate the scaling based on the final frame of viewToBeStretched (viewRect) vs the "fromRect"
CGFloat scaleX = ?, scaleY = ?;
CGAffineTransform scaleTransform = CGAffineTransformMakeScale(scaleX, scaleY);
//use translation instead of modifying the view's center, since frame changes with transforms are no good
CGFloat translationX = ?, translationY =?;
CGAffineTransform translationTransform = CGAffineTransformMakeTranslation(translationX, translationY);
CGAffineTransform final = CGAffineTransformConcat(scaleTransform, translationTransform);
return final;
}