UIView scale to 0 using CGAffineTransformMakeScale

∥☆過路亽.° 提交于 2020-01-01 08:45:09

问题


Is it possible to scale a UIView down to 0 (width and height is 0) using CGAffineTransformMakeScale?

view.transform = CGAffineTransformMakeScale(0.0f, 0.0f);

Why would this throw an error of "<Error>: CGAffineTransformInvert: singular matrix." ?



Update: There is another way of scaling down a UIView to 0

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:0.3]; 
view.frame = CGRectMake(view.center.x, view.center.y, 0, 0);

[UIView commitAnimations];

回答1:


There are lots of times when the underlying frameworks need to invert your transform matrix. The inverse of a matrix is some matrix M' such that the product of your matrix M and the inverse matrix M' is the identify matrix 1.

1 = M * M'

The zero matrix does not have an inverse, hence the error message.




回答2:


I'm not sure it's possible to do this; you'll start running into divide-by-zero issues. If you try to do this, you'll be creating a transform that looks like:

   0  0  0
   0  0  0
   0  0  1

Which, when applied to ANY other transform, will produce the above transform.

Why not just hide the view (if you want to scale it out of sight) or set the scaling factor to something like 0.001 (if you want to scale it in)?




回答3:


you could try:

CGAffineTransform transform = myView.transform;
myView.transform = CGAffineTransformScale(transform. 0.0f, 0.0f);

or inline the whole thing.



来源:https://stackoverflow.com/questions/216076/uiview-scale-to-0-using-cgaffinetransformmakescale

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!