본문 바로가기

iOS

[iOS] 뷰 회전 관련 작업 : viewWillTransition

viewWillTransition(to:with:)

Notifies the container that the size of its view is about to change.

뷰의 사이즈가 바뀔 때 호출되는 함수이다.

func viewWillTransition(to size: CGSize, 
                   with coordinator: UIViewControllerTransitionCoordinator)

size : 컨테이너 뷰의 새로운 사이즈

coordinator : 사이즈 변화를 관리하는 transition coordinator object (?????)

 

You can use a transition coordinator object to perform tasks that are related to a transition but that are separate from what the animator objects are doing. During a transition, the animator objects are responsible for putting the new view controller content onscreen, but there may be other visual elements that need to be displayed too. For example, a presentation controller might want to animate the appearance or disappearance of decoration views that are separate from the view controller content. In that case, it uses the transition coordinator to perform those animations.

(..아놔)


 

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
	print("transition")
	print(size.width)
}

디바이스를 회전시킬 때마다 viewWillTransition 함수가 호출된다.

변경된 뷰의 width를 print 하면 이렇게 잘 출력이 된다! 

(896.0 : 기기가 landscape 일 때, 414.0 : portrait)

'iOS' 카테고리의 다른 글

[iOS] 세그 (Segue)  (0) 2020.06.12
[iOS] UIRefreshControl  (0) 2020.06.12
[iOS] View의 Life-Cycle (생명주기)  (0) 2020.06.12
[iOS] UIVisualEffectView  (0) 2020.06.12
[iOS] 디자인 패턴 | Target - Action  (0) 2020.06.12