Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I adjust the anchor point of a CALayer, when Auto Layout is being used?
    primarykey
    data
    text
    <p><strong>Note</strong>: Things have moved on since this question was asked; see <a href="http://revealapp.com/blog/constraints-and-transforms.html" rel="noreferrer">here</a> for a good recent overview.</p> <hr> <p>Before auto layout, you could change the anchor point of a view's layer without moving the view by storing the frame, setting the anchor point, and restoring the frame. </p> <p>In an auto layout world, we don't set frames any more, but constraints don't seem up to the task of adjusting the position of a view back to where we want it to. You can hack the constraints to reposition your view, but on rotation or other resizing events, these become invalid again. </p> <p>The following bright idea doesn't work as it creates an "Invalid pairing of layout attributes (left and width)":</p> <pre><code>layerView.layer.anchorPoint = CGPointMake(1.0, 0.5); // Some other size-related constraints here which all work fine... [self.view addConstraint: [NSLayoutConstraint constraintWithItem:layerView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:layerView attribute:NSLayoutAttributeWidth multiplier:0.5 constant:20.0]]; </code></pre> <p>My intention here was to set the left edge of <code>layerView</code>, the view with the adjusted anchor point, to half of its width plus 20 (the distance I want inset from the left edge of the superview). </p> <p>Is it possible to change the anchor point, without changing the location of a view, in a view that is laid out with auto layout? Do I need to use hardcoded values and edit the constraint on every rotation? I do hope not. </p> <p>I need to change the anchor point so that when I apply a transform to the view, I get the correct visual effect. </p>
    singulars
    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.
 

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