The original link is received here: http://stackoverflow.com/questions/12943107/ how-do-i-adjust-the-anchor-point-of-a-calayer-when-auto-layout-is-being-used/14105757#14105757
The discussion is about the AutoLayout layout, where the view's transform is changed and the layout is triggered to cause confusion. These adaptation issues may no longer exist in IOS8, or at least have been weakened.
Problem: Transform in AutoLayout does have some compatibility issues, causing animation anomalies. As for the reason, my understanding is that once the AutoLayout is used, then its frame should be given to AutoLayout to deal with, and it should not be changed by changing the transform to modify its frame. The AutoLayout principle is to use the constraints in Layoutsubviews to set the frame of the view. In other words, constraints is just a queue of tasks that executes at layoutsubviews time. When I modify the transform of the view below, the theoretical result should be that the view is centered, but when the view has different constraints, we may see different effects:
V.transform = Cgaffinetransformmakescale (0.5,0.5);
It is also important to note that when you modify the transform of a view, layout is triggered immediately.
Solution: First, do not use constraints. Simply killing all the contraints will make the view disappear from the screen, and we need to make the view unaffected by AutoLayout by setting the translatesautoresizingmaskintoconstraints to Yes. If you think this program is more extreme, look at the following scenario. Ii. use constraints in a specific scenario if the size of the view mentioned in the first scenario is self-determined (such as fixed, or fit by content), and the location is determined based on the center point of the view, then the transform in the first scenario shows OK. Because of this situation, the constraints in AutoLayout does not affect the frame of the view. Third, the use of subview in front of two options have limited the advantages of AutoLayout, now talk about the need to limit the AutoLayout advantages of the scheme. Use constraint to lay out a host view, and then add the real view we want to lay out in the host view. is an example:
The white view is the host view, using any of the constraints to determine a location and set it to be transparent to the background. Use the Red view as its subview and the center alignment to determine the position of the red view in its white host view. In this way, we do not have any effect on the red view when zooming, rotating, and so on:
Self.otherView.transform = Cgaffinetransformscale (self.otherView.transform, 0.5, 0.5); self.otherView.transform = Cgaffinetransformrotate (Self.otherView.transform, m_pi/8.0);
Iv. using layer transforms to replace the view Transform with layer Transform will not trigger layout or conflict with constrants. For example, the following "Heartbeat" animation may be interrupted under AutoLayout:
[UIView animatewithduration:0.3 delay:0 options:uiviewanimationoptionautoreverse animations:^{ V.transform = Cgaffinetransformmakescale (1.1, 1.1);} completion:^ (BOOL finished) { v.transform = cgaffinetransformidentity;}];
But if we use core animation, there's no problem:
cabasicanimation* ba = [cabasicanimation animationwithkeypath:@ "transform"];ba.autoreverses = Yes;ba.duration = 0.3; Ba.tovalue = [Nsvalue Valuewithcatransform3d:catransform3dmakescale (1.1, 1.1, 1)]; [V.layer Addanimation:ba Forkey:nil];
Conflict between AutoLayout layout and transform in iOS