UIView: how to convert "reset". CGAffineTransformScale does not work as I would expect

I think that my question can be summarized how to store and reset the view transformation. But then perhaps an explanation of my situation may help.

If I applied the transforms below to the view one by one (for example, if I add this code to a radio button or button). I get exactly the result that I would expect: the scale switches between: a view that is .55 times the size of the original view, and a representation of the original scale on it. It also works for scaling someView submenu, just like me. Ad infinitum. Fine.

//tranformScale 1 someView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.55, 0.55 ); //tranformScale 2 someView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0 ); 

The problem is that I want to use this code (or similar) to scale the self.view subtask when the iOS device goes into landscape, to fit the landscape (and backup when in portrait) to the screen. It almost works, but for some reason, instead of displaying the values ​​of rounded values ​​for the scalable frame (as it happens with the test using the button for invoking transformations), strange values ​​are gradually produced. In the end, after about 4 turns, the subview flies out of the screen. I suspect this is due to a change in the form of self.view, but then again, when I register the self.view frame, its shape is very predictable.

By the way,. I focus on using autooresizingMask flexible fields without using auto-layout. maybe I should focus on another type of computation?

Thanks for reading!

+8
ios uiview autoresize
source share
2 answers

(1) do not forget to set or get any frame data after applying the transforms, it is not supported and will give unpredictable results;

(2) turn off the autoresist masking markers and position them like this:

  view.center = CGPointMake(view.superview.bounds.size.width/2, view.superview.bounds.size.height/2); 

(take care to apply centering while the view is full size, i.e. BEFORE the transformation, if it is a resizing transformation, AFTER the transformation, if it is an identity transformation)

+5
source share

I did this and it worked perfectly.

 self.imageview.transform = CGAffineTransformIdentity 
+28
source share

All Articles