I have a CATextLayer that I want to be able to vertically align within my view. I can set a constraint to align it to the top of the view, to the middle, or to the bottom; but I want to be able to allow the user to change this on the fly. When I set up my CATextLayer, I use this constraint to align it in the middle:
[textLayer addConstraint: [CAConstraint constraintWithAttribute:kCAConstraintMidY
relativeTo:@"superlayer"
attribute:kCAConstraintMidY]];
This works fine, but if I want to update the layer to align it to the top of the view I try:
[textLayer addConstraint: [CAConstraint constraintWithAttribute:kCAConstraintMaxY
relativeTo:@"superlayer"
attribute:kCAConstraintMaxY]];
When I add the new constraint it doesn't get aligned to the top, but goes past the top of the view where you can only see part of it. It looks like it is trying to apply both of the constraints. There is no removeConstraint and the same thing seems to happen if I define a CAConstraint variable on my class and just update that variable after adding it to the CATextLayer. Do I need to recreate the CATextLayer every time?