ios개발/개념 정리

<스위프트> 뷰컨트롤러 이동 1 : transition, present, show

studying develop 2020. 3. 4. 14:31

뷰컨트롤러 전반에 대해서는 <https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/PresentingaViewController.html#//apple_ref/doc/uid/TP40007457-CH14-SW1> 여기가 정말 자세한거 같다.

 

일단 첫 문단을 읽었는데 모르던 내용이 두개나 있다.

 

There are two ways to display a view controller onscreen: embed it in a container view controller or present it. Container view controllers provide an app’s primary navigation, but presenting view controllers is also an important navigation tool. You use direct presentation to display a new view controller on top of the current one. Typically, you present view controllers when you want to implement modal interfaces, but you can also use them for other purposes.

 

뷰컨을 화면에 보여주는 방법이 두개라 한다. embed와 present. 

여기서 컨테이너 뷰컨이 뭐지? 테이블 뷰컨, 콜렉팅 뷰컨 같은건가? 그리고 app's primary navigation이 뭐지?

모달 인터페이스를 구현해서 직접적으로 뷰컨을 보여주는데, 이 방법을 다른 목적에 사용할 수 도 있다 한다.

 

그리고 다음 문단에서 뷰컨을 띄우면 presenting 뷰컨과 presented 뷰컨 관계가 형성되고, presented vc가 해제 되야 이 관계가 끝난다 한다.

 

뷰컨을 새로운 화면에 보여주는 방법은 presenting vc가 가장 쉽고 빠른 방법이라 한다. presenting은 코드로 또는 세그로 시작할 수 있다 한다.

 

다루지 않겠지만 presentation style과 transition style이 다양하다.

 

presenting vs showing

 

presenting은 presenting 하는 vc를 모달하게 보여 줄 수 도있고, 자식으로 삼을 수  도 있다한다. 둘의 차이를 모르겠따...

반면에 presenting은 항상 modal하게 보여준다 함.

  • The showViewController:sender: and showDetailViewController:sender: methods offer the most adaptive and flexible way to display view controllers. These methods let the presenting view controller decide how best to handle the presentation. For example, a container view controller might incorporate the view controller as a child instead of presenting it modally. The default behavior presents the view controller modally.

  • The presentViewController:animated:completion: method always displays the view controller modally. The view controller that calls this method might not ultimately handle the presentation but the presentation is always modal. This method adapts the presentation style for horizontally compact environments.

 

The showViewController:sender: and showDetailViewController:sender: methods are the preferred way to initiate presentations. A view controller can call them without knowing anything about the rest of the view controller hierarchy or the current view controller’s position in that hierarchy. These methods also make it easier to reuse view controllers in different parts of your app without writing conditional code paths.

 

?? show가 presentation에 이상적인 방법이라 한다. 왜냐하면 뷰컨이 여타 다른 뷰컨들의 구조나 상하 관계에서 현재 뷰컨의 위치를 알 필요가 없기 때문이다. 이러한 방법들은 앱의 다른 부분에서 조건부 코드 사용 없이 뷰컨을 재사용하기 쉽다 한다. 음 읽고 보니, 뷰컨을 present 하는건 어쩌면 현재 뷰컨이 어떤 상태인지 알아야 될 수 도 있는 까다로운 일인가 보다. 왠지 모르겠다.

 

음 그리고 밑에 show하는 방법이랑 present하는 방법이 있는데 뭐가 다른건지 모르겠다.......

 

결론 모르겠다; 뭐가 뭔지