0

I have the following code which makes an oval rotating around its center. I would like to be able to position it within UIImageView at a certain position (say a middle of the view).

I would really appreciate if someone could help me out on this one.

-(void)drawCircle
{
CGMutablePathRef circlePath = CGPathCreateMutable();
int radius = 400;
CGRect circleRect = CGRectMake(CENTER_Y-radius*0.7, CENTER_X-radius, 1.4*radius, 2*radius);
float midX = CGRectGetMidX(circleRect);
float midY = CGRectGetMidY(circleRect);

CGAffineTransform transform = CGAffineTransformMakeTranslation(-midX, -midY);
CGPathAddEllipseInRect( circlePath ,&transform , circleRect);

CAShapeLayer *circle = [[CAShapeLayer alloc] init];
circle.path = circlePath;
circle.opacity = 0.1;
circle.contentsScale = SCREEN_SCALE;
circle.fillColor = [UIColor blueColor].CGColor;

[aView.layer addSublayer:circle];
CABasicAnimation* theAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
theAnimation.fromValue = 0;
theAnimation.toValue = @(2*M_PI);
theAnimation.duration=3.5;
theAnimation.autoreverses=FALSE;
theAnimation.repeatCount=HUGE_VALF;
theAnimation.fillMode = kCAFillModeBoth;
theAnimation.removedOnCompletion=FALSE;
theAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[circle addAnimation:theAnimation forKey:@"transform.rotation.z"];

}
IluTov
  • 6,807
  • 6
  • 41
  • 103
PrimeSeventyThree
  • 940
  • 2
  • 9
  • 24

1 Answers1

0

a missing piece:

[circle setPosition:CGPointMake(CENTER_X, CENTER_Y)];
PrimeSeventyThree
  • 940
  • 2
  • 9
  • 24
  • Is that part of the question or an actual answer to your question? Of it is extra information to your question you should edit the question instead of posting more information in an answer. (Edit button below in the lower left of your question) – David Rönnqvist Dec 29 '12 at 20:51
  • that's an answer to my question. – PrimeSeventyThree Dec 29 '12 at 21:22
  • Looks like you also neglected to set the bounds of your shape layer. `[circle setBounds:circleRect];` so I'm surprised it's displaying at all. – Matt Long Jan 26 '13 at 19:16