Skip to content

Instantly share code, notes, and snippets.

@uruly
Last active April 10, 2018 04:45
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/033dc6a0af9fa32145187466f9f1c862 to your computer and use it in GitHub Desktop.
Save uruly/033dc6a0af9fa32145187466f9f1c862 to your computer and use it in GitHub Desktop.
import UIKit
class CustomSegue: UIStoryboardSegue {
override func perform(){
//遷移前のViewControllerのインスタンスを作成
let firstVC = self.source
//遷移後のViewControllerのインスタンスを作成
let secondVC = self.destination
//このモックがsecondVCの動きになる
let mock = createMockView(view: secondVC.view)
firstVC.view.addSubview(mock)
//画面の横の長さを取得
let width = UIScreen.main.bounds.size.width
//画面の縦の長さを取得
let height = UIScreen.main.bounds.size.height
//右側からスライドさせる
mock.frame = CGRect(x:width,y:0,width:width,height:height)
UIView.animate(withDuration: 0.5, animations: {
mock.frame.origin.x = 0
}) { (isCompletion) in
if isCompletion { //連続タップ対策を一応
firstVC.present(secondVC, animated: false, completion: { mock.removeFromSuperview() })
}else { //失敗したらモックだけ片付ける
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