UI GameObject created in code has rotation that can't be modified

I am creating a new GameObject and set it as a child of another UI gameobject:

child = new GameObject("Child", typeof(RectTransform));
child.transform.SetParent(transform);

The UI gameobject I set as the parent:

alt text

It does not have rotation. The canvas, which has a rotation (automatically matches the camera rotation):

alt text

and the child object resulting from the code snippet:

alt text

As you can see somehow the child object gets the negative rotation of the canvas. However I can not edit the rotation in code.

child.transform.rotation = Quaternion.Euler(Vector3.zero);
child.transform.rotation = Quaternion.identity;

i tried this with both the Transform.rotation as well as the RectTransform.rotation and it will always reset back to the default rotation on play.

After crawling the doc some more I found out that Transform.SetParent has an overload with a bool worldPositionStays, which is true by default. Setting that to false eliminates the issue.