我想在视图上模拟“放大”。较大的视图将作为子视图添加到较小的视图的超级视图中,并且较大的视图应该看起来像是从较小的视图放大。给定小视图的矩形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;
}