When would a UIView's bounds.origin not be (0, 0)?

后端 未结 4 1028
遥遥无期
遥遥无期 2021-02-02 07:15

When would an UIView\'s bounds.origin not be (0, 0)?

This paragraph was helpful to me:

IMPORTANT!! Bounds X and Y, the

4条回答
  •  半阙折子戏
    2021-02-02 08:07

    The bounds.origin will be negative if you initialize a view with negative width/height. For example, if you did

    UIView* v = [[UIView alloc] initWithFrame:CGRectMake(5, 5, -10, -20)];
    

    the frame would be:

    origin = {
      x = -5, 
      y = -15
    }, 
    size = {
      width = 10, 
      height = 20
    }
    

    bounds:

    origin = {
      x = -10, 
      y = -20
    }, 
    size = {
      width = 10, 
      height = 20
    }
    

    center:

    x = 0, 
    y = -5
    

    try it for yourself!

提交回复
热议问题