0

I have TagView which is subclass of UIView. I'm rotating it around anchor point like so:

double rads = DEGREES_TO_RADIANS(self.angle);
[self setAnchorPoint:self.anchor forView:self];
CGAffineTransform transform = CGAffineTransformRotate(CGAffineTransformIdentity, rads);
self.transform = transform;

I'm setting anchor point using method proposed here:

- (void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view {
    CGPoint newPoint = CGPointMake(view.bounds.size.width * anchorPoint.x, 
                                   view.bounds.size.height * anchorPoint.y);
    CGPoint oldPoint = CGPointMake(view.bounds.size.width * view.layer.anchorPoint.x, 
                                   view.bounds.size.height * view.layer.anchorPoint.y);

    newPoint = CGPointApplyAffineTransform(newPoint, view.transform);
    oldPoint = CGPointApplyAffineTransform(oldPoint, view.transform);

    CGPoint position = view.layer.position;

    position.x -= oldPoint.x;
    position.x += newPoint.x;

    position.y -= oldPoint.y;
    position.y += newPoint.y;

    view.layer.position = position;
    view.layer.anchorPoint = anchorPoint;
}

I had an Auto Layout issue which I have fixed by placing my view into container UIView and setting it into center. But when I change the content of label which is inside my View it makes jump.

enter image description here

Zuzana Paulis
  • 941
  • 1
  • 8
  • 19

1 Answers1

0

I found the solution to my problem. I was setting blue view into center of fixed size UIView with Autolayout constraints. In my drawRect method I applied above mentioned setAnchorPoint method. Problem was, that when I have set new anchor point my constraints were not applied immediately. They applied after content was changed and moved blue Views position into center of the pink UIView as you can see on the image below.

enter image description here

Solution was to force superview to Layout its subviews.

Zuzana Paulis
  • 941
  • 1
  • 8
  • 19