[swift]bounds와 frame 움짤로 간단히 확인해보기

okstring·2021년 2월 24일
0

[swift]bounds와 frame의 차이

frame

The frame rectangle, which describes the view’s location and size in its superview’s coordinate system.

  • SuperView's coordenate system(수퍼 뷰의 좌표계)에서 뷰의 위치와 크기를 설명하는 프레임 사각형입니다.

  • 즉, 자신의 부모뷰를 기준으로 origin의 위치를 정하는 것이 frame

  • 참고로 여기서 origin은 x, y, size은 width, height

  • 인터페이스 빌더에서 보이는 x, y는 frame을 말한다

bounds

The bounds rectangle, which describes the view’s location and size in its own coordinate system.

  • own coordinate system(자체 좌표 시스템)에서 뷰의 위치와 크기를 설명하는 bound rectangle 입니다.
  • default bounds origin 은 (0, 0)

gif로 차이 확인해보기

animate를 활용해서 그려보고 이해했더니 더 와닿는 느낌이었다

frame

frame의 x를 50에서 0으로, frame의 y를 100에서 0으로

  • superView를 중심으로 움직이기 때문에 (0, 0)으로 설정하니 착 달라붙는 걸 볼 수 있다

bounds

bounds의 x를 0에서 30으로, bounds의 y를 0에서 80으로

  • 자기 자신의 좌표시스템(0, 0)에서 (30, 80)만큼 움직인 모습

reference

https://zeddios.tistory.com/203

https://zeddios.tistory.com/231

https://velog.io/@cskim/frame-vs-bounds

profile
step by step

0개의 댓글