@@ -38,11 +38,43 @@ extension UIView: Layoutable, SizeCalculable {
3838 }
3939
4040 public func getRect( keepTransform: Bool ) -> CGRect {
41- return layer. getRect ( keepTransform: keepTransform)
41+ if keepTransform {
42+ /*
43+ To adjust the view's position and size, we don't set the UIView's frame directly, because we want to keep the
44+ view's transform (UIView.transform).
45+ By setting the view's center and bounds we really set the frame of the non-transformed view, and this keep
46+ the view's transform. So view's transforms won't be affected/altered by PinLayout.
47+ */
48+ let size = bounds. size
49+ // See setRect(...) for details about this calculation.
50+ let origin = CGPoint ( x: center. x - ( size. width * layer. anchorPoint. x) ,
51+ y: center. y - ( size. height * layer. anchorPoint. y) )
52+
53+ return CGRect ( origin: origin, size: size)
54+ } else {
55+ return frame
56+ }
4257 }
4358
4459 public func setRect( _ rect: CGRect , keepTransform: Bool ) {
45- layer. setRect ( rect, keepTransform: keepTransform)
60+ let adjustedRect = Coordinates< View> . adjustRectToDisplayScale( rect)
61+
62+ if keepTransform {
63+ /*
64+ To adjust the view's position and size, we don't set the UIView's frame directly, because we want to keep the
65+ view's transform (UIView.transform).
66+ By setting the view's center and bounds we really set the frame of the non-transformed view, and this keep
67+ the view's transform. So view's transforms won't be affected/altered by PinLayout.
68+ */
69+
70+ // NOTE: The center is offset by the layer.anchorPoint, so we have to take it into account.
71+ center = CGPoint ( x: adjustedRect. origin. x + ( adjustedRect. width * layer. anchorPoint. x) ,
72+ y: adjustedRect. origin. y + ( adjustedRect. height * layer. anchorPoint. y) )
73+ // NOTE: We must set only the bounds's size and keep the origin.
74+ bounds. size = adjustedRect. size
75+ } else {
76+ frame = adjustedRect
77+ }
4678 }
4779
4880 public func isLTR( ) -> Bool {
0 commit comments