title: How can I reliably rotate an image around a point?
body: <p>I've read the following, from <a href="https://stackoverflow.com/questions/8275882/one-step-affine-transform-for-rotation-around-a-point">One step affine transform for rotation around a point?</a>:</p>
  
  <pre><code>CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y);
  transform = CGAffineTransformRotate(transform, a);
  transform = CGAffineTransformTranslate(transform,-x,-y);
  </code></pre>
  
  <p>However, when I do this the images transformed are all over the map, and rarely over the screen.</p>
  
  <p>I've tried a bit to make a system where it will place images; if you run a loop and place several values, a spiral appears. However, while I might be able to eventually untangle the relationship between a rotation of images and the points I wanted them to rotate about, I wanted to ask for the best solution to "I have an image here; I consider this point to be its center; I want it to be rotated by this amount around its center but not otherwise displaced."</p>
  
  <p>I am trying to make a modified port of <a href="http://JonathansCorner.com/ancient-clock/" rel="noreferrer">http://JonathansCorner.com/ancient-clock/</a>, and right now I am trying to place the hour hand. All attempts to do the song and dance above, and translate it so its center is at the desired center, have failed.</p>
  
  <p>How, for the hands of this clock, can I say "I want the hands in the following rotations" and have them appropriately placed around the center?</p>
  
  <p>--EDIT--</p>
  
  <p>The crucial part of this code, edited in an attempt to use layers in response to a comment, is:</p>
  
  <pre><code>UIImage *hourHandImage = [UIImage imageNamed:@"hour-hand.png"];
  UIImageView *hourHandView = [[UIImageView alloc] initWithImage:hourHandImage];
  float hourRotation = .5;
  hourHandImage = [UIImage imageNamed:@"hour-hand.png"];
  hourHandView = [[UIImageView alloc] initWithImage:hourHandImage];
  CGAffineTransform transform = CGAffineTransformMakeTranslation(centerX - 21, -centerY - 121);
  // transform = CGAffineTransformRotate(transform, hourRotation);
  // transform = CGAffineTransformTranslate(transform, 2 * centerX, 2 * centerY);
  hourHandView.transform = transform;
  hourHandView.layer.anchorPoint = CGPointMake(centerX, centerY);
  hourHandView.layer.affineTransform = CGAffineTransformRotate(transform, hourRotation);
  [self.view addSubview:hourHandView];
  </code></pre>
  
  <p>Thanks,</p>
  
  <p>--EDIT--</p>
  
  <p>I now have something pared down; if I follow some of the instructions, I have:</p>
  
  <pre><code>CGAffineTransform transform = CGAffineTransformMakeTranslation(100 -21, 100 -121);
  transform = CGAffineTransformRotate(transform, hour / 12.0 * M_PI * 2.0);
  transform = CGAffineTransformTranslate(transform, -330, 330);
  hourHandView.transform = transform;
  </code></pre>
  
  <p>I'd like to work on getting those numbers out, but this has an hour of 9:00 correctly displayed.</p>
  
  <p>Thanks for all your help!</p>