Rotate with the transform, then change the beginning of the frame, and the view expands?

This is a pretty quandry iPhone. I am working on a library but narrowing down my problem to very simple code. What this code does is create a 50x50 view, apply a rotation rotation of several degrees, and then shift the frame several times. As a result, the 50x50 view now looks much more attractive.

Here is the code:

// a simple 50x50 view UIView *redThing = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 50, 50)]; redThing.backgroundColor = [UIColor redColor]; [self.view addSubview:redThing]; // rotate a small amount (as long as it not 90 or 180, etc.) redThing.transform = CGAffineTransformRotate(redThing.transform, 0.1234); // move the view down 2 pixels CGRect newFrame = CGRectMake(redThing.frame.origin.x, redThing.frame.origin.y + 2, redThing.frame.size.width, redThing.frame.size.height); redThing.frame = newFrame; // move the view down another 2 pixels newFrame = CGRectMake(redThing.frame.origin.x, redThing.frame.origin.y + 2, redThing.frame.size.width, redThing.frame.size.height); redThing.frame = newFrame; // move the view down another 2 pixels newFrame = CGRectMake(redThing.frame.origin.x, redThing.frame.origin.y + 2, redThing.frame.size.width, redThing.frame.size.height); redThing.frame = newFrame; // move the view down another 2 pixels newFrame = CGRectMake(redThing.frame.origin.x, redThing.frame.origin.y + 2, redThing.frame.size.width, redThing.frame.size.height); redThing.frame = newFrame; 

So what happened? Now, if I move the view using translational conversion, it works fine. But this is not what I want to do, and it should work anyway.

Any ideas?

+6
iphone animation quartz-graphics
source share
1 answer

In the UIView documentation:

If the transform property is also set, use the values โ€‹โ€‹of the boundaries and properties of the center instead; otherwise, the animation of changes to the frame property does not correctly reflect the actual location of the view.

A warning. If the transform property is not an identity transformation, the value of this property is undefined and should therefore be ignored.

In other words, I would be wary of the frame property when transform set.

+14
source share

All Articles