简体   繁体   中英

UIView animateWithDuration does not work

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?

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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM