Do I have the right understanding of frames and bounds in UIKit?

后端 未结 5 1925
深忆病人
深忆病人 2020-12-23 20:55

Let me try to explain it. Please tell me if I am wrong. I am just 70% sure about it.

Like I understand it, an UIView has a frame and an bounds rectangle. The job of

相关标签:
5条回答
  • 2020-12-23 21:09

    Yes you are right.

    When you need to use the view, then you use the frame; the bounds are used to actually implement the view. As an example, you need to use the bounds to draw a view or to handle touch events. Instead, you use the frame when creating a view or positioning a view in its superview etc.

    0 讨论(0)
  • 2020-12-23 21:14

    A view's Frame: the position and size of a rectangle inside the superview where the view will fill.

    A view's Bound: the position and size of a rectangle inside the view itself.

    0 讨论(0)
  • 2020-12-23 21:18

    Check out Apple's guide on View Geometry. They have pretty good examples on what happens when you change bounds and frame values.

    0 讨论(0)
  • 2020-12-23 21:20

    You are right.

    You can use the two interchangably though it's just the frame is easier when using a view and bounds is easier when working inside a view (e.g. in the event handling or drawing code)

    Note also that frame is undefined if there is a transform operating on the view.

    0 讨论(0)
  • 2020-12-23 21:21

    http://developer.apple.com/library/ios/#documentation/windowsviews/conceptual/viewpg_iphoneos/WindowsandViews/WindowsandViews.html

    For iOS. Origin coordinate is in different location from Mac OS (upper left, not lower left)

    0 讨论(0)
提交回复
热议问题