UIKit Relative Frame Understanding

Ali Akhtar
3 min readApr 15, 2022

Orange View

In Figure 1 as you can see Orange View constraint from top 37 , height = 400 , leading and trailing = 0

Figure 1

In Figure 4 you will see the globalFrame which is distance of that view with window if specify nil , so for orange view there is no logic at all , since orange view is same frame with parent and window.

For figure 3 you can understand midX , minX and maxX, middle of that view with parent or global frame which is window same from minX and maxX

Figure 2
Figure 3
Figure 4

Green View

In Figure 5 as you can see Green View constraint

topToSuperView → topToOrangeView → 16

bottomToBlueView → 16

height → 100

leading and trailing to superView → leading and trailing to orangeView → 16

Figure 5

Figure 6, 7 you can observe

frame from parent it gives the value

Figure 6
Figure 7

For global frame you can see , just consider window as parent and neglect orange view so from window x = 16 , y = 128 + 16 = 144 is the only difference since for x perceptive parent view act as window but for y things change

Figure 8

Red View

16 points to parent which is green view from everywhere 4 side simple

Figure 9

Green View as parent Normal Flow

Figure 10
Figure 11

Global Frame (Window as parent View)

Figure 12
Figure 13

White View

16 points to parent which is red view from everywhere 4 sides simple

Red View as parent Normal Flow

Window as parent

Now this is very important White View with Parent GreenView instead of RedView , note we are only getting frame in respect to GreenView we are not changing parent view