SetTransform: CGAffineTransformMakeScale - Alternatives when trying to scale a UIView

I use the following to scale the view to 3x its original size:

[pageShadowView setTransform:CGAffineTransformMakeScale (3, 1)]; 

I would like to have a method that checks if my UIView (pageShadowView) is already scaled - in which case I would like to split it by 3 so that it returns to normal size.

I cannot think of any method that would do this. So I thought it might be better to check if my UIPageView has a specific size, and if it does not resize it to its original size.

So my question is, is there a UIView scaling method with a specific width and height that is not relative (i.e. 3 times) but expressed in pixels (e.g. 200 pixels x 300 pixels). I could not find anything in the documentation, which, to be honest, is a little on the head when it comes to the CGAffineTransform section.

Any suggestions would be much appreciated!

+4
source share
1 answer

To test the scaling of your view, we just need to check if its transform not an identity transformation.

 BOOL isScaled = ! CGAffineTransformIsIdentity(pageShadowView.transform); 

It should be noted that this check will be valid only if you do not use other types of transformation, that is, rotation or translation.

Scaling a UIView to a specific width and height is also easy:

 CGFloat yourDesiredWidth = 200.0; CGFloat yourDesiredHeight = 300.0; CGAffineTransform scalingTransform; scalingTransform = CGAffineTransformMakeScale(yourDesiredWidth/pageShadowView.bounds.size.width, yourDesiredHeight/pageShadowView.bounds.size.height); pageShadowView.transform = scalingTransform; 

It is important to check for UIView bounds instead of frame , because frame not valid when converting UIView .

+7
source

Source: https://habr.com/ru/post/1346465/


All Articles