0

I have a problem that hopefully has a simple solution. I am trying to create a bobbing effect using a button, a timer, frame, cgaffinetransformrotations, and delays. Everything would be great, except that when the button is rotated and I set the frame of the button to decrease or increase the y by 10 or so pixels, the rotation makes the frame of the button bigger than it normally is. The end result is a button that constantly grows until it swallows the screen.

I tried making the upward and downward movements cgaffinetranslations, but that uses the transform property (which is the same one that the rotations use). The result is a very jumpy and non-realistic bob.

What I am trying to accomplish is just to set the origin component of the frame without having to specify a width and height, because even specifying a hard-coded width and height still makes it shrink when it is rotating and grow when it is approaching equilibrium again.

Any ideas?

Thanks!

CODE:

- (void)movePlay{
[self performSelector:@selector(moveDown:) withObject:play];
[self performSelector:@selector(rotateRight:) withObject:play afterDelay:0];
[self performSelector:@selector(moveUp:) withObject:play afterDelay:0.5];
[self performSelector:@selector(rotateLeft:) withObject:play afterDelay:1];

}

- (void)moveUp:(UIButton*)log{

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
log.transform = CGAffineTransformMakeTranslation(0, -20);
[UIView commitAnimations];

}

- (void)rotateRight:(UIButton*)log{

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
log.transform = CGAffineTransformMakeRotation(0.0174532925*10);
[UIView commitAnimations];

}
Liftoff
  • 24,717
  • 13
  • 66
  • 119
  • Just a hint from the iOS reference library: "Warning If the transform property is not the identity transform, the value of this property (frame) is undefined and therefore should be ignored." Meaning, you should probably set bounds, instead of frame. – lukasz Apr 10 '12 at 00:57

1 Answers1

1

This is just an idea. Try combining all the separate transformations together. So instead of committing independently

log.transform = CGAffineTransfor..., 

combine them first with

CGAffineTransformConcat(CGAffineTransform t1, CGAffineTransform t2);
CGAffineTransformRotate(CGAffineTransform t1, CGFloat angle);
etc.
lukasz
  • 771
  • 5
  • 11