본문 바로가기
#모바일 [Mobile]/iOS

[iOS] UIViewController 생명주기 (Life Cycle)

by cy_mos 2021. 10. 24.
반응형
카테고리 (Category) 작성 날짜 (Write Date) 최근 수정 날자 (Recent Write Date) 작성자 (Writer)
iOS 2021.10.24. 18:30 2024.02.29. 22:53 Dev.Yang

 

[iOS] UIViewController Life Cycle

 

# UIViewController 상태 변화 메서드

뷰가 나타나거나 사라지는 등 뷰가 화면에 보이는 상태가 변화할때 호출되는 메서드입니다. 아래의 내용들은 각 메서드가 호출 될때의 시점과 수행에 적합한 작업들의 내용입니다.

 

🛠 ViewDidLoad

override func viewDidLoad() {
        super.viewDidLoad()
 }

 

  • 뷰 계층이 메모리에 로드된 직후 호출되는 메서드입니다.
  • 뷰의 초기화 작업이 필요한 경우에 사용되는 메서드이며, 메모리에 처음 로딩 될때 1회 호출되고 메모리 경고로 뷰가 사라지지 않는 이상 다시 호출되지 않습니다.

🛠 ViewWillAppear

override func viewWillAppear(_ animated: Bool) { 
	super.viewWillAppear(animated)
}

 

  • 뷰가 뷰 계층에 추가되고 화면이 표시되기 직전에 호출되는 메서드입니다.
  • 뷰의 추가적인 초기화 작업을 하거나 다른 뷰로 이동했다가 되돌아오면 재호출되는 메서드로, 화면이 나타날때마다 수행해야하는 작업을 할 때 사용하는 메서드입니다.

 

아래의 접은 글은 Apple Developer Document 내용입니다.

더보기

🇺🇸 Called just before the view controller’s content view is added to the app’s view hierarchy. 


Use this method to trigger any operations that need to occur before the content view is presented onscreen. Despite the name, just because the system calls this method, it does not guarantee that the content view will become visible. The view may be obscured by other views or hidden. This method simply indicates that the content view is about to be added to the app’s view hierarchy.


🛠 ViewDidAppear

override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
}

 

  • 뷰가 뷰 계층에 추가되어 화면이 표시되면 호출되는 메서드입니다.
  • 뷰를 나타내는 것과 관련된 추가적인 작업이 필요하는 경우에 사용되는 메서드입니다.

 

아래의 접은 글은 Apple Developer Document 내용입니다.

더보기

🇺🇸 Called just after the view controller’s content view has been added to the app’s view hierarchy.

 

Use this method to trigger any operations that need to occur as soon as the view is presented onscreen, such as fetching data or showing an animation. Despite the name, just because the system calls this method, it does not guarantee that the content view is visible. The view may be obscured by other views or hidden. This method simply indicates that the content view has been added to the app’s view hierarchy.


🛠 ViewWillDisappear

override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
}

 

  • 뷰가 뷰 계층에서 사라지기 직전에 호출되는 메서드입니다.
  • 뷰가 생성된 뒤 발생한 변화를 이전상태로 되돌리는 작업이 필요하는 경우에 사용되는 메서드입니다.

 

아래의 접은 글은 Apple Developer Document 내용입니다.

더보기

🇺🇸 Called just before the view controller’s content view is removed from the app’s view hierarchy. 

 

Use this method to perform cleanup tasks like committing changes or resigning the first responder status. Despite the name, the system does not call this method just because the content view will be hidden or obscured. This method is only called when the content view is about to be removed from the app’s view hierarchy.


🛠 ViewDidDisappear

override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
}

 

  • 뷰가 뷰 계층에서 사라진 후 호출되는 메서드입니다.
  • 뷰를 숨기는 것과 관련된 추가적인 작업을 할 때 사용하며 시간이 오래 걸리는 작업은 하지 않습니다.

 

아래의 접은 글은 Apple Developer Document 내용입니다.

더보기

🇺🇸 Called just after the view controller’s content view has been removed from the app’s view hierarchy. 

 

Use this method to perform additional teardown activities. Despite the name, the system does not call this method just because the content view has become hidden or obscured. This method is only called when the content view has been removed from the app’s view hierarchy.


# UIViewController Layout 변화 메서드

뷰가 생성된 후 바운드 및 위치 등의 레이아웃에 변화가 발생했을 때 호출되는 메서드입니다. 

 

🛠 ViewWillLayoutSubviews

override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
}

 

  • 뷰가 서브뷰의 레이아웃을 변경하기 직전에 호출되는 메서드입니다.
  • 서브뷰의 레이아웃을 변경하기 전에 수행할 작업이 필요한 경우 사용되는 메서드입니다.

아래의 접은 글은 Apple Developer Document 내용입니다.

더보기

🇺🇸 Called to notify the view controller that its view is about to layout its subviews.

 

When a view's bounds change, the view adjusts the position of its subviews. Your view controller can override this method to make changes before the view lays out its subviews. The default implementation of this method does nothing.


🛠 ViewDidLayoutSubviews

override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
}

 

  • 서브뷰의 레이아웃이 변경된 후 호출되는 메서드입니다.
  • 서브뷰의 레이아웃을 변경 한 후 추가적인 작업이 필요한 경우 사용되는 메서드입니다.

 

아래의 접은 글은 Apple Developer Document 내용입니다.

더보기

🇺🇸 Called to notify the view controller that its view has just laid out its subviews. 

 

When the bounds change for a view controller's view, the view adjusts the positions of its subviews and then the system calls this method. However, this method being called does not indicate that the individual layouts of the view's subviews have been adjusted. Each subview is responsible for adjusting its own layout. 

Your view controller can override this method to make changes after the view lays out its subviews. The default implementation of this method does nothing.


🚀 REFERENCE

반응형

댓글