Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My current solution is to manually adjust the layer's position in <code>viewDidLayoutSubviews</code>. This code could also be used in <code>layoutSubviews</code> for a view subclass, but in my case my view is a top-level view inside a view controller, so this meant I didn't have to make a UIView subclass. </p> <p>It seems like too much effort so other answers are most welcome. </p> <pre><code>-(void)viewDidLayoutSubviews { for (UIView *view in self.view.subviews) { CGPoint anchorPoint = view.layer.anchorPoint; // We're only interested in views with a non-standard anchor point if (!CGPointEqualToPoint(CGPointMake(0.5, 0.5),anchorPoint)) { CGFloat xDifference = anchorPoint.x - 0.5; CGFloat yDifference = anchorPoint.y - 0.5; CGPoint currentPosition = view.layer.position; // Use transforms if we can, otherwise manually calculate the frame change // Assuming a transform is in use since we are changing the anchor point. if (CATransform3DIsAffine(view.layer.transform)) { CGAffineTransform current = CATransform3DGetAffineTransform(view.layer.transform); CGAffineTransform invert = CGAffineTransformInvert(current); currentPosition = CGPointApplyAffineTransform(currentPosition, invert); currentPosition.x += (view.bounds.size.width * xDifference); currentPosition.y += (view.bounds.size.height * yDifference); currentPosition = CGPointApplyAffineTransform(currentPosition, current); } else { CGFloat transformXRatio = view.bounds.size.width / view.frame.size.width; if (xDifference &lt; 0) transformXRatio = 1.0/transformXRatio; CGFloat transformYRatio = view.bounds.size.height / view.frame.size.height; if (yDifference &lt; 0) transformYRatio = 1.0/transformYRatio; currentPosition.x += (view.bounds.size.width * xDifference) * transformXRatio; currentPosition.y += (view.bounds.size.height * yDifference) * transformYRatio; } view.layer.position = currentPosition; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload