How to know the current scale of a UIView?

uiview scale
uiview scale animation
cgaffinetransform
cgaffinetransform scale and translate
swift view transform scale
uiimageview transform scale
resize uiview swift
swift shrink view

How do you find the current scale (zoom level) of a UIView?

If you're applying a scale transform to your view, that transform will be available (appropriately enough) through the transform property on UIView. According to the CGAffineTransform docs, scale transforms will have nonzero values at coordinates (1,1) and (2,2) in the transform matrix; you can therefore get your x- and y-scale factors by doing:

CGFloat xScale = view.transform.a;
CGFloat yScale = view.transform.d;

Get view controller current scale, d;. After applying a scale transform, a transformation will be available through the transform property (CGAffineTransform values) on UIView. How to get the current drawings scale I am trying to get scale factor of whole drwaing using c# code.I am able to get only single entities scale factor. So does any body have solution for this?

According to this source, using this method gives you the scale regardless of rotation or translation applied to transform:

func scale(from transform: CGAffineTransform) -> Double {
    return sqrt(Double(transform.a * transform.a + transform.c * transform.c));
}

I know I am late to the party but the accepted answer didn't work in my case.

How to find the scale from a CGAffineTransform, If you have a CGAffineTransform and want to know what its scale component is – regardless of whether it has been rotated or translated – use  If you need to know which window is key, observe the did Become Key Notification and did Resign Key Notification notifications. The system sends those notifications in response to key window changes in your app. To force a window become key, or to force a window to resign the key status, call the appropriate methods of this class.

Check this it will help you .... In this you can learn how to set minimum and maximum zoom scale using UIPinchGestureRecognizer .... How to set minimum and maximum zoom scale using UIPinchGestureRecognizer

transform, Discussion. Use this property to scale or rotate the view's frame rectangle within its superview's coordinate system. (To change the position of the view, modify  Knowing the current scale is given by the transformation matrix. The scale values, as you know, are here: sx, 0, 0 0 , sy, 0 . . .. ,1. To get the current state, just record the transform's state. To return to that state, however, you'll need to use the inverse of your last transformation or load the identity matrix. share.

That functionality is provided with UIScrollView and it's zoomScale property.

EDIT:

Knowing the current scale is given by the transformation matrix. The scale values, as you know, are here:

sx, 0,  0
0 , sy, 0
. . .. ,1. 

To get the current state, just record the transform's state. To return to that state, however, you'll need to use the inverse of your last transformation or load the identity matrix.

contentScaleFactor, UIView; contentScaleFactor The scale factor determines how content in the view is mapped from the logical coordinate space frame size is 50 x 50 points, the size of the bitmap used to present that content is 100 x 100 pixels. environment, see Supporting High-Resolution Displays in OpenGL ES Programming Guide. I simply want the layout of the iPad Air to scale up to fill the iPad Pro size. If you use some standard UI elements like UICollectionView, the cells scale up automatically to fill the entire screen. I would like to replicate this behavior with the UIView.

Isn't that the contentScaleFactor (reference)?

UIView Transformations and Animations, When you see UIKit functions that offer an animated parameter, you know you can These transforms allow you to scale, rotate, shear, translate, and with setting a property will implicitly change it from its current state to the specified state. A navigation controller object manages an optional toolbar in its view hierarchy. When displayed, this toolbar obtains its current set of items from the toolbar Items property of the active view controller. When the active view controller changes, the navigation controller updates the toolbar items to match the new view controller, animating

Problem when animating a UIView to scale to zero using , The approach I took was to apply a CGAffineTransform (with scale factor set to… the scaleTransform matrix and the current UIView transform (lets call this To see how this looks in an iOS app, please check the “expected  I was working on an iPhone app development project where one of the app features demanded to get the rotation and scale factor of the UIView. Here is a short article on how I utilised the CGAffineTransform in my application. The current transformation of the UIView is already stored in its transform property.

Scaling a UIView with subviews staying the same size, We know that a matrix multiplied by its inverse matrix will result in an identity matrix. In terms of UIView transforms this means that if we multiply  How to scale fill a UIView with an image issue did not scale the image correctly into the UIView's size. thing because you want to know during development if

Understanding UIView's transform property (final), Understanding UIView's transform property (final) context of this article, but if you wonder and want to learn more, this wiki would be a good start. However, usually, we use only scale and rotation of transform as for translation, we can simply use center Post was not sent - check your email addresses! You can do this in Interface Builder: 1) Control-drag from a frame view (e.g. questionFrame) to main View, in the pop-up select “Equal heights”. 2)Then go to size inspector of the frame, click edit “Equal height to Superview” constraint, set the multiplier to 0.7 and hit return.

Comments
  • are you using scrollView for zooming ?
  • No, I use UIPinchGestureRecognizer and CGAffineTransformScale.
  • I already tried but it did not work. I made ​​a mistake somewhere in this case. Thanks for your response !
  • As a note here: It works well if the view was scaled only. However, it will got a wrong value when the view was also rotated. @Margaret 's answer works in this case then, i.e. sqrt(Double(transform.a * transform.a + transform.c * transform.c)).
  • I know and I can't use UIScrollView for this project, not powerful enough =/
  • During the scale modification, this value doesn't change so I think it's not for this use.
  • While this code snippet may solve the question, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.