Clockwise / counterclockwise rotation when touched

Any idea on how to rotate an image clockwise / counterclockwise when touched.

0
source share
3 answers
#import <QuartzCore/QuartzCore.h> 

[UIView beginAnimations:@"RotationAnimation" context:nil];

CABasicAnimation *fullRotationAnimation;
fullRotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotationAnimation .fromValue = [NSNumber numberWithFloat:0];
fullRotationAnimation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
fullRotationAnimation.duration = 2;          // speed for the rotation. Smaller number is faster
fullRotationAnimation.repeatCount = 1e100f;  // number of times to spin. 1 = once
[myImage.layer addAnimation:fullRotationAnimation forKey:@"360"];

[UIView commitAnimations];
+4
source

You want to use CoreAnimation for this; basically you need to apply animation to the transform property of your image. There are many samples on the Apple Developers page that show variations of this.

0
source

, -..
CGAffineTransformMakeRotation,

-(void)rotate
    {
        x++;
        CGAffineTransform transform = CGAffineTransformMakeRotation(x);
        imageView.transform = transform;
        [self performSelector:@selector(rotate) withObject:self afterDelay:0.1];

    }  

To guide ClockWise use x -;

0
source

Source: https://habr.com/ru/post/1783652/


All Articles