Reputation: 1473
Hy,
I my application I want to animate an UIView by changing it's position and rotation at the same time. The issue is that sometimes the animation is changing the width and height of the UIView.
The animation code is this one:
int shuffleFrameX = (int)self.gameView.frame.size.width - (int)myView.frame.size.width;
int shuffleFrameY = (int)self.gameView.frame.size.height - (int)myView.frame.size.height;
int x = arc4random()%shuffleFrameX;
int y = arc4random()%shuffleFrameY;
CGRect newFrame = CGRectMake(x, y, myView.frame.size.width, myView.frame.size.height);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
if(isPieceRotationActive)
{
int fact = arc4random()%4;
myView.transform = CGAffineTransformMakeRotation(DegreesToRadians(90*fact));
[myView setPieceRotation:fact];
}
[myView setFrame:newFrame];
[UIView commitAnimations];
This animation is repeated between 2 and 5 times using a the delegate functions. I did not copied them here.
Any idea what am I doing wrong?
Thanks!
Upvotes: 1
Views: 2698
Reputation: 397
Change/Adapt your code to use this sequence:
Something like this:
Good luck!
Upvotes: 2
Reputation: 5112
I think you should be using bounds instead of frame. The frame will increase in size as a rotation is made on a rectangle to hold the rotated rectangle, the bounds will not since the bounds represents the internal coordinates of the rotated rectangle
Upvotes: 2