title: Rotating a view using another view's center as the anchor point
body: <p>I have two image views. The first is the blueish arrow, and the second is the white circle, with a black dot drawn to represent the center of the circle. </p>
  
  <p><img src="https://i.stack.imgur.com/CRAdd.png" alt=""></p>
  
  <p>I'm trying to rotate the arrow so it's anchor point is the black dot in the picture like this</p>
  
  <p><img src="https://i.stack.imgur.com/DP3zh.gif" alt="enter image description here"></p>
  
  <p>Right now I'm setting the anchor point of the arrow's layer to a point calculated like this</p>
  
  <pre><code>CGFloat y = _userImageViewContainer.center.y - CGRectGetMinY(_directionArrowView.frame);
  CGFloat x = _userImageViewContainer.center.x - CGRectGetMinX(_directionArrowView.frame);
  CGFloat yOff = y / CGRectGetHeight(_directionArrowView.frame);
  CGFloat xOff = x / CGRectGetWidth(_directionArrowView.frame);
  
  _directionArrowView.center = _userImageViewContainer.center;
  
  CGPoint anchor = CGPointMake(xOff, yOff);
  NSLog(@"anchor: %@", NSStringFromCGPoint(anchor));
  
  _directionArrowView.layer.anchorPoint = anchor;
  </code></pre>
  
  <p>Since the anchor point is set as a percentage of the view, i.e. the coords for the center are (.5, .5), I'm calculating the percentage of the height in arrow's frame where the black dot falls. But my math, even after working out by hand, keeps resulting in .5, which isn't right because it's further than half way down when the arrow is in the original position (vertical, with the point up). </p>
  
  <p>I'm rotating based on the user's compass heading</p>
  
  <pre><code>CLHeading *heading = [notif object];
  
  // update direction of arrow
  CGFloat degrees = [self p_calculateAngleBetween:[PULAccount currentUser].location.coordinate
                                              and:_user.location.coordinate];
  
  
  _directionArrowView.transform = CGAffineTransformMakeRotation((degrees - heading.trueHeading) * M_PI / 180);
  </code></pre>
  
  <p>The rotation is correct, it's just the anchor point that's not working right. Any ideas of how to accomplish this?</p>