Search code examples
iosswiftxcodeanimationsegue

custom segue that moves only part of content xcode


I have seen a lot of tutorial but did not see any interesting me. I want to make custom segue that moves only one view, not the whole page.

Something like this:

enter image description here

Top view is just poping without any animation. But bottom view normally slides on bottom viewcontroler

I have tried:

swift

override func perform() {
    scale()
}
func scale(){
    let toViewController = self.destination
    let fromViewController = self.source

    let containerView = fromViewController.view.superview
    let originalCenter = fromViewController.view.center

    toViewController.view.viewWithTag(1)?.viewWithTag(2)?.transform = CGAffineTransform(translationX:self.source.view.frame.width,y:0)
    toViewController.view.center = originalCenter

    containerView?.addSubview(toViewController.view)

    UIView.animate(withDuration: 0.5, delay:0, options: .showHideTransitionViews ,animations:{
        toViewController.view.viewWithTag(1)?.viewWithTag(2)?.transform = CGAffineTransform.identity
    },completion:{success in fromViewController.present(toViewController,animated: false,completion: nil)})
}

If you do not understand, ask me and help me please.


Solution

  • I think you need this hierarchy

    enter image description here

    MainView
      -topView
      -containerView 
       -navigation
         -firstvc
         -secondvc
    

    and set navigationBar to hidden in storyboard

    enter image description here