본문 바로가기

iOS

[swift3] custom segue transition animation

# 오른쪽화면이 왼쪽으로 이동하며 등장 (right to left)

# 왼쪽화면이 오른쪽으로 이동하며 등장 (left to right)



import UIKit
class SegueRightToLeft: UIStoryboardSegue {
override func perform() {
let src = self.source
let dst = self.destination
src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)
dst.view.transform = CGAffineTransform(translationX: src.view.frame.size.width, y: 0)
UIView.animate(withDuration: 0.25, delay: 0.0, options: .curveEaseInOut,
animations: {
dst.view.transform = CGAffineTransform(translationX: 0, y: 0)
},
completion: { finished in
src.present(dst, animated: false, completion: nil)
})
}
}
class SegueLeftToRight: UIStoryboardSegue {
override func perform() {
let src = self.source
let dst = self.destination
src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)
dst.view.transform = CGAffineTransform(translationX: -src.view.frame.size.width, y: 0)
UIView.animate(withDuration: 0.25, delay: 0.0, options: UIViewAnimationOptions.curveEaseInOut, animations: {
dst.view.transform = CGAffineTransform(translationX: 0, y: 0)
}) { (finished) in
src.present(dst, animated: false, completion: nil)
}
}
}



# 적용 : Segument 선택 > Attributes Inspector 탭 > 

             Kind = Custom 선택, Class = SegueLeftToRight 또는 SegueRightToLeft 선택





끝.