2017-12-19 3 views
0

이 내 뷰 컨트롤러/SEGUE 설정입니다 : Screenshot of Interface Builder푸시 연속 후 소스보기 컨트롤러가 사라지지 않게하려면 어떻게해야합니까? 우선

세 오른쪽 뷰 컨트롤러의 배경 뷰 소스 뷰 컨트롤러가 표시되어야 통해 UIVisualEffectViews 있습니다. 설정이 컨트롤러를보기를 통해

let blurEffect = UIBlurEffect(style: .dark) 
let blurEffectView = UIVisualEffectView(effect: blurEffect) 
blurEffectView.frame = self.view.bounds 
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] 

self.tableView.backgroundView = blurEffectView 

이제 기본보기 컨트롤러 (이하 "쓰레기 날"하나)이 표시되지만 설정이 VC는 두 때마다 하나 사라 : 그들은이 같은 다양한 viewDidLoad()들에 추가되었습니다 가장 오른쪽의 VCs 완전히 화면에 있습니다. 여기에 화면 녹화는 다음과 같습니다

Screen recording of the source view controller dis- and reappearing

내가 기술적으로 표시 SEGUE "는이 없음을 얻을

(나는이 분명히 비디오를 손상 업로드하는 데 사용되는 응용 프로그램을 글리치를 무시하십시오) Over Current Context "와 같기 때문에 소스 VC가 사라지지 않을 것이라고 기대해서는 안되지만, 커스텀 씨젠 (custom segues)없이이 작업을 할 수있는 방법이 있어야한다.

답변

1

보기 컨트롤러간에 사용자 지정 전환을 만드는 것이 좋습니다. 다음을 수행하여 UINavigationController 클래스에서

class AnimationController: NSObject, UIViewControllerAnimatedTransitioning 
{ 
    var pushing = true 

    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { 
     return 0.3 
    } 

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { 
     let duration = transitionDuration(using: transitionContext) 

     let toVc = transitionContext.viewController(forKey: .to)! 
     let toView = transitionContext.view(forKey: .to)! 

     let fromView = transitionContext.view(forKey: .from)! 

     let container = transitionContext.containerView 

     if pushing { 
      container.addSubview(fromView) 
      container.addSubview(toView) 
     } 

     var finalFrame = transitionContext.finalFrame(for: toVc) 
     if pushing { 
      finalFrame.origin.x = finalFrame.width 
      toView.frame = finalFrame 
      finalFrame.origin.x = 0 
     } else { 
      finalFrame.origin.x = finalFrame.width 
     } 

     UIView.animate(withDuration: duration, delay: 0, options: .curveEaseOut, animations: { 
      if self.pushing { 
       toView.frame = finalFrame 
      } else { 
       fromView.frame = finalFrame 
      } 
     }) { (_) in 
      transitionContext.completeTransition(true) 
      if self.pushing { 
       container.insertSubview(fromView, belowSubview: toView) 
      } else { 
       fromView.removeFromSuperview() 
      } 
     } 
    } 
} 

:

class NavigationController: UINavigationController { 

    let animationController = AnimationController() 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     delegate = self 
    } 
} 

그리고이 확장 : 그러나

extension NavigationController: UINavigationControllerDelegate 
{ 
    func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { 

     animationController.pushing = operation == .push 

     return animationController 
    } 
} 

, 이것은 당신을 만드는

난 그냥 쓴이 클래스를 테스트 대화 형 해제 제스처를 잃습니다 (화면 왼쪽에서 스 와이프하여 닫음). 너 자신을 고칠 필요가있어.

+0

그건 내가 두려워하는 것입니다. 전환 코드를 보내 주셔서 감사합니다. 그러나 나는 단지 흐린 배경을 완전히 삭제할 것입니다. –

관련 문제