Skip to content

Instantly share code, notes, and snippets.

@uruly
Created April 10, 2018 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uruly/4f58ae413f4b672c7de09967bd55f589 to your computer and use it in GitHub Desktop.
Save uruly/4f58ae413f4b672c7de09967bd55f589 to your computer and use it in GitHub Desktop.
import UIKit
class CustomUnwindSegue: UIStoryboardSegue {
override func perform(){
//遷移前のViewControllerのインスタンスを作成
let firstVC = self.source
//遷移後のViewControllerのインスタンスを作成
let secondVC = self.destination
let mock = createMockView(view: firstVC.view)
secondVC.view.addSubview(mock)
//画面の横の長さを取得
let width = UIScreen.main.bounds.size.width
//画面の縦の長さを取得
let height = UIScreen.main.bounds.size.height
mock.frame = CGRect(x:0,y:0,width:width,height:height)
//先にdismissをする
self.source.dismiss(animated: false, completion: {
UIView.animate(withDuration: 0.5, animations: {
mock.frame.origin.x = width
}) { (isCompletion) in
mock.removeFromSuperview()
}
})
}
func createMockView(view: UIView) -> UIImageView {
UIGraphicsBeginImageContextWithOptions(view.frame.size, true, UIScreen.main.scale)
view.drawHierarchy(in: view.bounds, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return UIImageView(image: image)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment