IOS setTransform overridden setFrame? Convert without re-drawing after re-running setFrame

My transform is not drawn after the frame is redrawn using setFrame.

I scale the view when the orientation changes using setFrame. But this opinion should also change position depending on the BOOL argument: On = up in view, off = down off screen. I use setTransform to adjust the position of the view.

First, I draw a view by executing setFrame . This leads to the fact that the picture of 100 points is outside the screen below. Then I set the transform (-100 to ty) to bring it to the viewpoints (while BOOL set to TRUE , otherwise the transform is 0 and the view is turned off).

 [view setFrame:CGRectMake(0, self.view.bounds.size.height, self.view.bounds.size.width, 100)]; [view setTransform:CGAffineTransformMake(1, 0, 0, 1, 0, -100)] 

This works fine, as expected, but when the orientation changes and this code is re-run (to resize the view), the transformation is not drawn, even if it is registered as a view transformation. In other words, the view is just off-screen, as if transform.ty was 0.

 Log message before re-draw: view.transform.ty -10.000000 Log message after re-draw: view.transform.ty -10.000000 

Any help?

+4
source share
1 answer

The frame view is a value that is derived from three basic values: bounds , center and transform . The installer for frame tries to do the right thing by changing the process, but may not always work correctly if the transform non-identifier is set.

The documentation is pretty clear:

If the transform property is not an identical transform, the value is undefined and should therefore be ignored.

...

If the transform property contains a non-identical transformation, the value of the frame property is undefined and should not be changed. In this case, you can move the view using the center property and adjust the size using the bounds property.

Since your transform only translates the view, I see no reason to use it at all. Just change the start of the view:

 [view setFrame:CGRectMake(0, self.view.bounds.size.height - 100, self.view.bounds.size.width, 100)]; 
+8
source

All Articles