ZZomato·Tech KnowledgeL3DSA Round

Frame vs Bounds in iOS

Problem Explain the difference between frame and bounds on a UIView in iOS.

Be ready to discuss

  • frame: the view's origin and size expressed in its superview's coordinate system, i.e. where the view sits inside its parent.
  • bounds: the view's origin and size in its own coordinate system, with origin normally (0,0) unless the content is scrolled or the coordinate space is shifted.
  • How applying a transform (rotation or scale) changes frame - it becomes the smallest axis-aligned rectangle enclosing the transformed view - while bounds stays unchanged.
  • Why frame is undefined/unreliable for a non-identity transform, and why you should set bounds + center instead of frame in that case.
  • Scroll views: UIScrollView scrolls by mutating bounds.origin (equivalently contentOffset), which is why subview frames don't change as you scroll.
  • Setting bounds.size resizes the view around its center without moving it in its own coordinate space; setting frame.size resizes around the origin.
  • Practical consequences for layout maths, hit testing, and converting points between views with convert(_:to:).
asked …
LeaderboardSalaryAccount