Scroll View School · Frames and Bounds | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/9223-scroll-view-school/lessons/2

Hi,
This is a great series of videos. But I think there is a small error though. The video states that in the case of bounds, “positive y is up” (around 0:58). I think this is a mistake. Here is why

  1. Apple’s documents clearly say “iOS. The default coordinate system has its origin at the upper left of the drawing area, and positive values extend down and to the right from it. You cannot change the default orientation of a view’s coordinate system in iOS—that is, you cannot “flip” it.” Coordinate system

  2. Another way to prove this subclass UIView, override draw(_ rect and actually draw something at a given point with positive coordinates
    override func draw(_ rect: CGRect) {
    let imagef = UIImage(named: "foo”)!
    imagef.draw(at: CGPoint(x: 100, y: 100))
    }

    You will see the image would appear near the top left.
    Please let me know what you think

Hi! Thanks for your comment and welcome to the community!

So, I was aiming for describing a simpler mental model, but that was undercut by my diagram being wrong (+x should be left, there!), and probably not the best way to go about it. Mainly, my point was that visually moving a view down the screen via the frame’s origin, and visually moving its contents down via the bounds origin requires you to change the y values in opposite directions.

We’ll look into fixing this video up in the future. It may be better to imagine the bounds rectangle as representing a sort of viewport into the subviews of a view, and the frame as the thing that defines where that bounds rectangle goes.