2016-10-24 6 views
3

버튼을 누른 다음 뷰 컨트롤러가 슬라이드 할 수있는 커스텀 세그를 만드는 가장 좋은 방법은 무엇입니까? 나는 왼쪽에서 오른쪽으로 세그 (segue)를 만들었지 만 나는 다른 방향으로 가고 싶다. 일부 Youtube 개의 동영상과 this question을 보았지만 내가 원하는 것을 보여주지 못했습니다.커스텀 슬라이드 Segue - Xcode 8.0 Swift 3.0

내 코드 :

import UIKit 

class SegueFromLeft: UIStoryboardSegue 
{ 
    override func perform() 
    { 
     let src = self.sourceViewController 
     let dst = self.destinationViewController 

     src.view.superview?.insertSubview(dst.view, aboveSubview: src.view) 
     dst.view.transform = CGAffineTransformMakeTranslation(-src.view.frame.size.width, 0) 

     UIView.animateWithDuration(0.25, 
      delay: 0.0, 
      options: UIViewAnimationOptions.CurveEaseInOut, 
      animations: { 
       dst.view.transform = CGAffineTransformMakeTranslation(0, 0) 
      }, 
      completion: { finished in 
       src.presentViewController(dst, animated: false, completion: nil) 
      } 
     ) 
    } 
} 

는 기본적으로, 오른쪽에서 왼쪽으로가는 SEGUE을 만들려고합니다.

감사

나는

+0

당신은이 일을 성공 했습니까? 내 대답을 시도 했니? –

답변

4

이 시도 엑스 코드 8.0 스위프트 3.0을 사용하고 있습니다 :

class SegueFromLeft: UIStoryboardSegue{ 
    override func perform(){ 
     let src=sourceViewController 
     let dst=destinationViewController 
     let slide_view=destinationViewController.view 

     src.view.addSubview(slide_view) 
     slide_view.transform=CGAffineTransform.init(translationX: src.view.frame.size.width, 0) 

     UIView.animateWithDuration(0.25, 
      delay: 0.0, 
      options: UIViewAnimationOptions.CurveEaseInOut, 
      animations: { 
       slide_view.transform=CGAffineTransform.identity 
     }, completion: {finished in 
       src.present(dst, animated: false, completion: nil) 
       slide_view.removeFromSuperview() 
     }) 
    } 
} 
0

스위프트 3.1 :

class ProceedToAppStoryboardSegue: UIStoryboardSegue { 

    override func perform(){ 

     let slideView = destination.view 

     source.view.addSubview(slideView!) 
     slideView?.transform = CGAffineTransform(translationX: source.view.frame.size.width, y: 0) 

     UIView.animate(withDuration: 0.25, 
           delay: 0.0, 
           options: UIViewAnimationOptions.curveEaseInOut, 
           animations: { 
           slideView?.transform = CGAffineTransform.identity 
     }, completion: { finished in 

      self.source.present(self.destination, animated: false, completion: nil) 
      slideView?.removeFromSuperview() 
     }) 
    } 
} 
관련 문제