{"id":7992,"date":"2015-11-16T01:02:08","date_gmt":"2015-11-16T01:02:08","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/16\/dasdom-ddhcustomtransition\/"},"modified":"2022-08-30T15:03:04","modified_gmt":"2022-08-30T15:03:04","slug":"dasdom-ddhcustomtransition","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/16\/dasdom-ddhcustomtransition\/","title":{"rendered":"dasdom\/DDHCustomTransition"},"content":{"rendered":"<p>Helper classes to make basic view controller transitions easier<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/raw.githubusercontent.com\/dasdom\/DDHCustomTransition\/master\/DDHCustomTransition\/what.gif\" \/><\/p>\n<h2>Installation<\/h2>\n<p>Add <strong>CustomTransition.swift<\/strong> to your project.<\/p>\n<h2>Usage<\/h2>\n<ol>\n<li>Create an instance of <code>NavigationControllerDelegate<\/code> and set to the delegate property of an <code>UINavigationController<\/code>.<\/li>\n<li>Make the view controllers participating in the transition conforming to the <code>TransitionInfoProtocol<\/code> protocol.<\/li>\n<li>There is no step three.<\/li>\n<\/ol>\n<h2>TransitionInfoProtocol<\/h2>\n<p>The <code>TransitionInfoProtocol<\/code> defines two required and one optional methods:<\/p>\n<pre><code>\/\/ Return the views which shoud be animated in the transition\nfunc viewsToAnimate() -&gt; [UIView]\n\n\/\/ Return a copy of the view which is passed in. The passed in view is one of the views to animate\nfunc copyForView(subView: UIView) -&gt; UIView\n\n\/* Optionally return the frames for the views which should be\n   animated. This is needed sometimes because for example\n   with custom container view contrllers the transitioning code\n   can't figure out where on screen the view is actually visible\n   when loaded. *\/\noptional func frameForView(subView: UIView) -&gt; CGRect\n<\/code><\/pre>\n<p>Let\u2019s say you want to animate a image view from the first view controller to the position of the second view controller (see the gif and the demo project). In the first view controller the protocol conformance could look like this:<\/p>\n<pre><code>import UIKit\n\nclass ViewController: UIViewController, TransitionInfoProtocol {\n\n    @IBOutlet weak var imageView: UIImageView!\n    @IBOutlet weak var label: UILabel!\n    \n    func viewsToAnimate() -&gt; [UIView] {\n        return [imageView, label]\n    }\n    \n    func copyForView(subView: UIView) -&gt; UIView {\n        if subView == imageView {\n            let imageViewCopy = UIImageView(image: imageView.image)\n            imageViewCopy.contentMode = imageView.contentMode\n            imageViewCopy.clipsToBounds = true\n            return imageViewCopy\n        } else if subView == label {\n            let labelCopy = UILabel()\n            labelCopy.text = label.text\n            labelCopy.font = label.font\n            labelCopy.backgroundColor = view.backgroundColor\n            return labelCopy\n        }\n        return UIView()\n    }\n}\n<\/code><\/pre>\n<p>In the second view controller it could look like this:<\/p>\n<pre><code>import UIKit\n\nclass DetailViewController: UIViewController, TransitionInfoProtocol {\n\n    @IBOutlet weak var imageView: UIImageView!\n    @IBOutlet weak var label: UILabel!\n    \n    func viewsToAnimate() -&gt; [UIView] {\n        return [imageView, label]\n    }\n    \n    func copyForView(subView: UIView) -&gt; UIView {\n        if subView == imageView {\n            let imageViewCopy = UIImageView(image: imageView.image)\n            imageViewCopy.contentMode = imageView.contentMode\n            imageViewCopy.clipsToBounds = true\n            return imageViewCopy\n        } else if subView == label {\n            let labelCopy = UILabel()\n            labelCopy.text = label.text\n            labelCopy.font = label.font\n            labelCopy.backgroundColor = label.backgroundColor\n            return labelCopy\n        }\n        return UIView()\n    }\n}\n<\/code><\/pre>\n<h2>Author<\/h2>\n<p>Dominik Hauser<\/p>\n<p>App.net: @dasdom<\/p>\n<p>Twitter: @dasdom<\/p>\n<p>swiftandpainless.com<\/p>\n<h2>Licence<\/h2>\n<p>MIT<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Helper classes to make basic view controller transitions easier Installation Add CustomTransition.swift to your project. Usage Create an instance of NavigationControllerDelegate and set to the delegate property of an UINavigationController. Make the view controllers participating in the transition conforming to the TransitionInfoProtocol protocol. There is no step three. TransitionInfoProtocol The TransitionInfoProtocol defines two required and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7992","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7992","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7992"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7992\/revisions"}],"predecessor-version":[{"id":8716,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7992\/revisions\/8716"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7992"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7992"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7992"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}