Note: Things have moved on since this question was asked; see here for a good recent overview.
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.
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.
The following bright idea doesn't work as it creates an "Invalid pairing of layout attributes (left and width)":
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]];
My intention here was to set the left edge of
layerView, 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).
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.
I need to change the anchor point so that when I apply a transform to the view, I get the correct visual effect.