Junior — Middle
Can you give an example when the element frame and its boundaries do not match in size?
sobes.tech AI
Answer from AI
In iOS, the frame of a UIView describes the position and size of the element relative to its superview, while the bounds describe the internal coordinate system of the element itself.
An example where the frame and bounds do not match in size is when a UIView has a transform applied, such as scaling or rotation. In this case, the frame will be calculated considering the transformation and may differ from the bounds.
let view = UIView(frame: CGRect(x: 50, y: 50, width: 100, height: 100))
view.transform = CGAffineTransform(scaleX: 2, y: 2)
print(view.frame) // frame will increase considering the scale
print(view.bounds) // bounds will remain (0,0,100,100)
Here, the bounds remains the same, while the frame changes, reflecting the new size and position after the transformation.