1

I have a UIView object. It rotates when I change global variable angle. I have a function that removes this UIView from it's superview and redraws it. I have added a button. When user presses this button I need to launch an animation. In every step I need to change the angle and call my redraw function. So so effect I'm expecting to see is that my view is rotating. here's the code:

-(IBAction)animate:(id)sender
{
    NSLog(@"animate: called");
    [UIView animateWithDuration:0.7
                          delay:0.0
                        options: UIViewAnimationCurveEaseOut
                     animations:^{
                     angle=angle+5.0;
                     if (angle>360)
                     {
                         angle=angle-360;
                     }
                     else if(angle<0)
                     {
                         angle=angle+360;
                     };

                     NSLog(@"inner angle: %g", angle);
                     [self transform]; //this is my redraw function. it redraws my view depending on global variable value angle.
                 } 
                 completion:NULL];
NSLog(@"finalAngle: %g", angle);
}

Why this animation does not working normally?

WendiKidd
  • 4,333
  • 4
  • 33
  • 50
Oleg
  • 1,383
  • 4
  • 19
  • 35
  • my NSLog output is: animate: called inner angle: 5 transform: called finalAngle: 5 transform: called – Oleg Dec 05 '11 at 13:29
  • it looks like the block in animateWithDuration works only 1 time. Where can I point him how many times I need him to work during 0.7 seconds? – Oleg Dec 05 '11 at 13:32
  • It animates, but my when I call "animate" my view rotates from the 0 angle but not from the previous value (which is 5 degrees lower) – Oleg Dec 05 '11 at 13:45
  • Why the starting point of this animation is 0 angle. But not the current value that changes by +5 degrees everytime I call animate? – Oleg Dec 05 '11 at 13:48
  • Maybe this happens because I'm setting anchor point and using myView.layer.transform function in my redraw function? – Oleg Dec 05 '11 at 13:52
  • 1
    It's a little unclear what you're going for. Is there a reason you can't just use yourView.transform = CGAffineTransformMakeRotation((M_PI * YOUR_ANGLE_HERE) / 180.0); in your animation block? – Darek Rossman Dec 05 '11 at 13:53
  • I just want to increase my angle by 5 degrees and to call [self transform] function every animation step. – Oleg Dec 05 '11 at 14:26
  • my view is drawing with function [self transform]. I want to rotate my view. So I'm increasing my global variable angle by 5 and calling transform function again. If I'm doing so without adding animation effect to this everything works fine but my view rotates imidiately. But I need it to rotate with animation. It rotates. BUT! It starts rotating **from the 0 degrees value to my angle+5 value**. I need it to rotate **from my current angle value to angle+5 value** – Oleg Dec 05 '11 at 14:35
  • Darek, I can not use such functions. Here's th уaprt of my redraw function `[block.layer setAnchorPoint:CGPointMake(0.5, 1.0)]; [block setFrame:CGRectMake(block.frame.origin.x, block.frame.origin.y+block.frame.size.height/2.0, block.frame.size.width, block.frame.size.height)]; CATransform3D basicTrans = CATransform3DIdentity; double rangle; basicTrans.m34 =1.0/-distance; rangle=angle/360*(2.0*M_PI); block.layer.transform = CATransform3DRotate(basicTrans, rangle, 1.0f, 0.0f, 0.0f); [block setCenter:CGPointMake(block.center.x, block.center.y-(oldHeight-newHeight))]; – Oleg Dec 05 '11 at 14:44

2 Answers2

1

UIView animation only supports the following properties

@property frame
@property bounds
@property center
@property transform
@property alpha
@property backgroundColor
@property contentStretch

you have to perform the animation with core animation framework

changx
  • 1,937
  • 1
  • 13
  • 10
0

You can animate the transform property. However, to perform a rotation with the transform property is more complex than using the CA Framework. I found this post helpful: UIView Infinite 360 degree rotation animation?

Community
  • 1
  • 1
  • Welcome to SO! It's preferred that you include some more details from the linked source, not just a link. – Emil Oct 03 '12 at 14:10