2017-02-21 7 views
0

내가, 내 UINavigationControllerrootViewController를 변경하고 내 원래 UINavigationController로 다시 변경 한 후 UISplitViewController 모두가 마스터 및 세부 쇼 시작 문제로 실행 해요 컴팩트 세로 방향에 대한 세부 사항을 표시 할 UISplitViewController 원인 컴팩트/세로 방향으로 전화 장치에서 볼 수 있습니다 (크기가 더 큰 전화기뿐 아니라 다른 전화기에서도 가능).

아키텍처의 기본 개요 : TabBarController에는 여러 개의 탭이 있습니다. 이 탭 중 하나는 UISplitViewController입니다. 저는 현재 MasterViewController 컴팩트 방향에 표시되어 있는지 확인하려면 다음을 오버라이드 (override) : 이것은 잘 작동하고 예상대로 세로의 마스터를 표시

func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool { 

    // this prevents phone from going straight to detail on showing the split view controller 
    return true 
} 

. 내가 디스플레이로 새로 UINavigationController 생성에 rootViewController을 변경하려면 아래에하고 있어요있는 그것을 새로운 UINavigationController 인스턴스를 생성하고 표시 할 수 있습니다 다른 탭에서 버튼을 누르면 어떤 점에서 :

let appDelegate = UIApplication.shared.delegate 
appDelegate?.window??.rootViewController = newNavVC 

가 On이 기각, I 위의 동일한 코드를 통해 UINavigationController을 원래의 것으로 다시 바꿔 넣을 수 있습니다. 그러나 한 번 (nav/display/dismiss 만들기) 한 번 UISplitViewController이있는 탭으로 다시 전환하면 병존하는 마스터 세부 정보보기로 바뀝니다. 소형 크기 조정을 위해 세로 모드에서 가능하다는 것을 알지 못했습니다. UISplitViewController에서 4 가지 기본 디스플레이 모드로 변경하려고 시도했지만 해결되지 않았습니다.

다음은 (iPhone 6 시뮬레이터와 유사합니다.) 위임자가 없거나 붕괴에 대한 오해가 있습니까?

전 : enter image description here

후 : 이 enter image description here

답변

1

당신은 대체 할 수있는 링크에서 발견 된 코드로 rootViewController을 할당 논리 :

Leaking views when changing rootViewController inside transitionWithView

기본 그냥 루트 뷰 컨트롤러를 올바르게 설정할 UIWindow 클래스의 확장을 만들면됩니다.

extension UIWindow { 

/// Fix for https://stackoverflow.com/a/27153956/849645 
func set(rootViewController newRootViewController: UIViewController, withTransition transition: CATransition? = nil) { 

    let previousViewController = rootViewController 

    if let transition = transition { 
     // Add the transition 
     layer.add(transition, forKey: kCATransition) 
    } 

    rootViewController = newRootViewController 

    // Update status bar appearance using the new view controllers appearance - animate if needed 
    if UIView.areAnimationsEnabled { 
     UIView.animate(withDuration: CATransaction.animationDuration()) { 
      newRootViewController.setNeedsStatusBarAppearanceUpdate() 
     } 
    } else { 
     newRootViewController.setNeedsStatusBarAppearanceUpdate() 
    } 

    /// The presenting view controllers view doesn't get removed from the window as its currently transistioning and presenting a view controller 
    if let transitionViewClass = NSClassFromString("UITransitionView") { 
     for subview in subviews where subview.isKind(of: transitionViewClass) { 
      subview.removeFromSuperview() 
     } 
    } 
    if let previousViewController = previousViewController { 
     // Allow the view controller to be deallocated 
     previousViewController.dismiss(animated: false) { 
      // Remove the root view in case its still showing 
      previousViewController.view.removeFromSuperview() 
     } 
    } 
} 
+1

귀하가 누군지 또는 왜 게시하고 있는지 알려줄 필요가 없습니다. 여기에서 쉽게 읽을 수 있도록 링크에서 관련 비트를 인용하십시오. – nloewen

+0

팁 주셔서 감사! 답변 수정 됨. –