Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to do self rotating CALayer
    text
    copied!<p>When i Clicked on view its create a star shape path.</p> <p>Now i want to spin the star which is added to CALayer.</p> <p>Can any one help me out.... How to spin the CALayer on iphone.</p> <pre><code>-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch=[touches anyObject]; currentPoint=[touch locationInView:self.view]; CGMutablePathRef starPath; rootLayer = [CALayer layer]; rootLayer.frame = self.view.bounds; [self.view.layer addSublayer:rootLayer]; starPath = CGPathCreateMutable(); CGPathMoveToPoint(starPath, NULL,currentPoint.x,currentPoint.y+15.0f); for(int i = 1; i &lt; 5; ++i) { CGFloat x =15.0*sinf(i * 4.0 * M_PI/5.0); CGFloat y =15.0*cosf(i * 4.0 * M_PI/5.0); CGPathAddLineToPoint(starPath, NULL,currentPoint.x+x,currentPoint.y+y); } CGPathCloseSubpath(starPath); shapeLayer=[CAShapeLayer layer]; shapeLayer.path = starPath; fillColor = [UIColor colorWithHue:0.825 saturation:1 brightness:1 alpha:1.0]; shapeLayer.fillColor = fillColor.CGColor; [rootLayer addSublayer:shapeLayer]; CGPathRelease(starPath); float zDistance=30; CATransform3D aTransform=CATransform3DIdentity; aTransform.m34=1.0/-zDistance; rootLayer.sublayerTransform=aTransform; [self addAnimationToLayer:rootLayer]; } -(void)addAnimationToLayer:(CALayer *)layer { CABasicAnimation *theAnimation; theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; theAnimation.fromValue=[NSNumber numberWithDouble:M_PI_2]; //theAnimation.toValue=[NSNumber numberWithFloat:6.0f*M_PI/180.0f]; theAnimation.duration=100; // theAnimation.autoreverses=TRUE; theAnimation.speed=100; theAnimation.repeatCount=10; [layer addAnimation:theAnimation forKey:@"transform"] ; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload