I would like to implement basic rotation animation in iOS, where the view rotates continuously around its center point.
However, for some reason, the pivot point is always the original view of the parent view, and not the rotating view center.
Thus, the view rotates around the upper left corner of the screen, even if I manually set the anchor point.
That's what I'm doing:
// Add shape layer to view CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init]; CGRect shapeRect = CGRectMake(0, 0, 100, 100); UIBezierPath *roundedRect = [UIBezierPath bezierPathWithRoundedRect:shapeRect cornerRadius:5]; shapeLayer.path = roundedRect.CGPath; shapeLayer.anchorPoint = CGPointMake(0.5, 0.5); shapeLayer.fillColor = [[UIColor redColor] CGColor]; [self.view.layer addSublayer:shapeLayer]; // Set rotation animation CATransform3D rotationTransform = CATransform3DMakeRotation(M_PI, 0, 0, 1); CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform"]; rotationAnimation.toValue = [NSValue valueWithCATransform3D:rotationTransform]; rotationAnimation.duration = 1.0f; rotationAnimation.cumulative = YES; rotationAnimation.repeatCount = HUGE_VALF; [shapeLayer addAnimation:rotationAnimation forKey:@"transform"];
Any help would be appreciated.
source share