Difference between frame.size.width and frame.width

后端 未结 3 1794
梦毁少年i
梦毁少年i 2020-12-17 16:15

I was writing a program in swift and just now I noticed that I can directly access a CGRect frame\'s width and height properties directly without using the

3条回答
  •  清酒与你
    2020-12-17 16:57

    frame is of CGRect structure, apart from its width and height have only getters, they can only be positive. From the documentation:

    Regardless of whether the height is stored in the CGRect data structure as a positive or negative number, this function returns the height as if the rectangle were standardized. That is, the result is never a negative number.

    However, size is of CGSize structure, from the documentation:

    A CGSize structure is sometimes used to represent a distance vector, rather than a physical size. As a vector, its values can be negative. To normalize a CGRect structure so that its size is represented by positive values, call the standardized function.

    So the difference is obvious.

提交回复
热议问题