Created
April 10, 2018 04:58
-
-
Save uruly/4f58ae413f4b672c7de09967bd55f589 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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