[iOS] UISplitViewController

Youngwoo Lee·2021년 7월 31일
0

iOS

목록 보기
32/46
post-thumbnail

참고자료

iOS Developer's Document - UISplitViewController 해석


Split View

Container View 중 하나로 계층형 interface 에서 Child View Controller들을 관리하는 View이다. interface 내에서 하나의 View Controller의 변경 내용을 다른 View Controller 드라이브의 내용을 변경한다.

Split View interface는 Note 앱과 같은 앱에서 content를 navigating 하는 것과 content를 filtering하는 것에 가장 적합한 Interface이다. 기본 사이드 바에서 폴더를 선택하면 해당 폴더에 있는 노트 목록이 표시되고, 목록에 노트를 선택하면 secondary view에서 특정 노트의 내용이 표시가 됩니다.

UI를 빌드할 때, Split ViewController는 app 화면의 root view controller이다. Split ViewControllers의 경우 고유한 모양은 없다. 대부분의 모양은 내장되는 하위 view controller에 의해 정의된다

Note
split view controller를 navigation stack에 push할 수 없다. 일부 다른 container view controller에 하위 view controller로 split view controller를 둘 수는 있지만, 대부분의 경우 그렇게 하지 않는 것이 좋다


Split View Styles

iOS14 버전 이후부터는 UISplitViewController는 column-style 레이아웃을 지원한다. 적절한 style을 init(style:) 이니셜라이져와 함께 이용하면 두개 혹은 세개의 column들을 가진 interface를 생성할 수 있다.

  • UISplitViewController.Style.doubleColumn 스타일을 사용하면 아래와 같이 두 개의 열로 이루어진 split ViewController가 생성된다. 이 split ViewController의 경우는 primary 와 secondary column에 배치된 두 개의 하위 뷰 컨트롤러를 관리한다.
  • UISplitViewController.Style.tripleColumn 스타일을 사용하면 아래와 같이 세 개의 열로 이루어진 split ViewController가 생성된다. 이 split ViewController의 경우는 primary 와 secondary, supplementary에 배치된 세 개의 하위 뷰 컨트롤러를 관리한다.

iOS 14버전 이전에, UISplitViewController는 오직 primary view controller와 secondary view controller를 가진 하나의 split view interface style만을 지원했었다. 이 interface는 .unspecified 유형인데 iOS14 이후의 column-style API에는 응답하지 않는다.


Child View Controllers

column-style split view interface에서 setViewController(_: for:)viewController(for:) 메서드를 사용하여 각 column의 view controllers들을 지정한다. Split View Controller 같은 경우는 모두 navigation controller 에 둘러쌓여 있는다. 만약에 Child ViewControllernavigation controller에 감싸지 않느낟고 하더라도, Split ViewController 가 자동으로 navigation controller를 감싸준다.

Split ViewControllerviewController(for:) 를 통해서 original view controller를 반환하지만 children property은 뷰 컨트롤러를 wrapping하는데 사용한 navigation controller를 포함합니다. view controller를 특정 열에 할당한 후 show( :) 또는 hide( : ) 메서드를 사용하여 이러한 열을 표시하거나 숨길 수 있다


기존의 split view controller에서는, view controller를 viewControllers property를 사용하여 Interface Builder 와 programatically에서 할당할 수 있었다. 그리고 primary, secondary view controller를 변경해줘야할 때는 show(_ : sender)showDetailViewController(_ : sender: ) 메서드를 추천했다. 이러한 메서드를 사용하여서 수정하는 것( property인 viewControllers를 이용하는 것에 비해)은 현재 display mode와 size class에 가장 적합한 방식으로 볼 수 있다


Interface Transitions

split view controller는 인터페이스의 특정 변경 사항에 대응하여 축소 및 확장 전환을 수행합니다. 예를 들어, 인터페이스의 size class가 수평으로 compactregular 속성 사이를 왔다갔다 전환한다면, column이 숨겨지거나 표시되거나 하는 식으로 전환이 발생할 것입니다. split View Controller는 delegate 객체를 통해서 축소, 확장 전환이 수행된다.

column style view interface에서 인터페이가 축소되면 primary, supplementary, secondary가 아닌 다른 view Controller를 보여줄 수도 있다. UISplitViewController.Column.compact column에 대해서 setViewController(_ : for: ) 메서드를 사용하여 설정한다. 만약에 좀 더 이러한 전환에 대해서 customize하고 싶다면, Column-Style Split Views. 를 참고하자. 그리고 classic 한 split view controller에 대한 관리는 이 곳을 참조하면 된다 Classic Split Views.


Display Mode

split view controller 의 현재 display mode는 child view controller 의 시각적 배열을 나타낸다. 화면에 나타나는 child view controller들 수와 정렬을 정할 수 있다. 예를 들어서, child view controller가 side bar 영역에서 나란히 나타나더라도, 한 번에 하나씩만 나타날 것인지, 혹은 동시에 나타나지만 하나만 주목받도록 할 것인지 정해줄 수 있다.

display mode를 정할 때는 바로 정할 수는 없고, preferredDisplayMode 프로퍼티를 통해서 정할 수 있다. 하지만 이렇게 한다고 반드시 display mode가 적용되는 것은 아닌데, 왜냐하면 space constraint 때문이다. 예를들어, split view controller 는 가로로 compact인 환경에서는 child view controller 들을 side에 표시할 수 없다.

기본 디스플레이 모드를 설정한 후에는 split view controller가 자체적으로 업데이트되고 실제 디스플레이 모드는 displayMode 프로퍼티에 반영됩니다. 만약에 어떤 column이 보여지기를 원하는지 변경하고 싶다면, show(_:) 혹은 hide(_:) 메서드를 사용하면 된다. split view controller는 원하는 column을 표시하도록 display mode를 업데이트하는 방법을 결정 할 것이다.


Gesture and Button Support

유저가 현재 display mode를 바꾸도록 할 수 있게 하는 방법이 여러 가지 있다.

Split View Controller 내부에는 gesture recognizer가 포함되어 있는데, 이는 swipe 를 통해서 유저가 display mode를 변경하는 것을 알 수 있게 한다. 물론, 우리는 해당 swipepresentsWithGesture 프로퍼티를 false 값으로 변경함으로써 제어할 수 있다.

만약에 presentsWithGesture 프로퍼티 값이 false라면 우리는 primary view controller 를 항상 볼 수 있을 것이다.

But, true 값 이라면, split view controller 는 display mode를 바꾸는 버튼을 가지고 있을 것이다. split view controlle 는 이 버튼의 행동(behavior), 모양(appearance), 위치(positioning) 까지도 관리해줄 수 있다.

UISplitViewController는 사이드 바 토글 아이콘로써 사용되는 UISplitViewController.SplitBehavior.titleback-chevron 아이콘으로써 사용되는 UISplitViewController.SplitBehavior.overlayUISplitViewController.SplitBehavior.displace를 나타냅니다. 이 버튼을 누르면 현재 디스플레이 모드 및 split View의 동작에 따라 새로운 디스플레이 모드로 전환됩니다.


3- column의 split View interface - UISplitViewController.Style.tripleColumn - 의 경우 디스플레이 모드에 영향을 미치는 또 다른 property는 showsSecondaryOnlyButton 이다. 이 property가 참이면, split View Controller는 UISplitViewController.DisplayMode.secondaryOnly에서, 혹은 해당 mode로 변경하기 위한 toggle bar button item을 만든다.


split View Controller는 behavior, appearance 그리고 item의 위치를 관리한다. 이 아이콘은 이중 화살표 아이콘입니다. 사용자가 이 버튼을 누르면 디스플레이 모드가 UISplitViewController.DisplayMode.secondaryOnly로 전환됩니다.

Split Behavior

split view controller에서 split behavior은 secondary view controller 가 다른 view controller와 비교하여 나타나지는 방식을 제어합니다. 우리는 secondary view controller 가 side에서 다른 view controller 에 비해 분명하게 나타나게 할 것인지, 혹은 어둡게 하여 스크린에서 잘 안보이게 할 지를 설정할 수 있습니다

Column Width Customization

Column의 너비 커스터마이징

split view interface의 primary, supplementary column 들의 width를 custom 해줄 수 있다. preferredPrimaryColumnWithdthFractionpreferredSupplementaryColumnWithFraction property 를 사용해주면 된다. 만약에 이 property들을 통해 값을 지정해주지 않는다면 automaticDimension 이 default 값이다. 그리고 system이 사용가능한 공간을 기준으로 적절한 behavior을 결정해준다.

Message Forwarding(메세지 보내기)

split View controller는 앱의 창과 하위 view controller 간에 상호 작용한다. 따라서 하위 view controller에 대한 모든 메시지 split view controller를 통해 이동한다. 예를 들어서, view의 나타남과 사라짐에 대한 메세지는 오직 해당 viewcontroller가 실제로 화면에 나타날 때만 전송됩니다.

State Preservation(상태 보존)

만약에 split view controller의 restorationIdentifier property에 값을 할당한다면, 이 property는 고유한 restorationIdentifier가 있는 유효한 child view controller를 만들게 됩니다. 다음 launch cycle 동안, split view controller는 split view controller는 보존된 view controller를 이전 상태로 복원한다. split view controller의 하위 view controller는 동일한 restorationIdentifier 를 사용할 수 있다. split view controller는 추가 정보를 자동으로 저장하여 각 하위의 restoration 경로가 고유한지 확인한다.

profile
iOS Developer Student

0개의 댓글