Sobes.tech
Junior — Middle

Is the value of origin always equal to zero in bounds?,

sobes.tech AI

Answer from AI

In iOS, the CGRect structure, which describes a rectangle, contains a field called origin — a point with x and y coordinates. The origin value of bounds is not always zero, but in most cases, it is (0, 0). This is because bounds describe the internal coordinates of the object itself (for example, a UIView), and its coordinate system usually starts at (0, 0).

However, there are situations where the origin of bounds can differ from zero, such as when using transformations or if bounds are intentionally changed to shift the internal coordinate system.

Example:

let view = UIView(frame: CGRect(x: 50, y: 50, width: 100, height: 100))
print(view.frame.origin)  // (50, 50)
print(view.bounds.origin) // usually (0, 0)

Thus, the origin of bounds is usually zero, but not always guaranteed.

Is the value of origin always equal to zero in… - sobes.tech