{"id":5039,"date":"2014-03-12T11:50:35","date_gmt":"2014-03-12T07:50:35","guid":{"rendered":"http:\/\/blog.denivip.ru\/?p=5039"},"modified":"2014-04-07T11:48:38","modified_gmt":"2014-04-07T07:48:38","slug":"how-to-use-uidynamicanimator-in-ios7-apps","status":"publish","type":"post","link":"http:\/\/blog.denivip.ru\/index.php\/2014\/03\/how-to-use-uidynamicanimator-in-ios7-apps\/?lang=en","title":{"rendered":"How to Use UIDynamicAnimator in iOS7 Apps"},"content":{"rendered":"<p>With the release of iOS 7 developers got empowered by many new tools to make fascinating effects and animations in their apps. However applicability of many of them is still in question. As soon as we made ourselves familiar with them, in <a title=\"PhotoSuerte\" href=\"http:\/\/photosuerte.com\" target=\"_blank\">our new project<\/a> we decided to make  a new animation, similar to that used by Apple in Messages. <!--more--><\/p>\n<p>To implement the behaviour, we had to replace the initially chosen instance of <a title=\"UITableView\" href=\"https:\/\/developer.apple.com\/library\/ios\/documentation\/uikit\/reference\/UITableView_Class\/Reference\/Reference.html#\/\/apple_ref\/occ\/cl\/UITableView\" target=\"_blank\">UITableView<\/a> class by <a title=\"UICollectionView\" href=\"https:\/\/developer.apple.com\/library\/ios\/documentation\/uikit\/reference\/UICollectionView_class\/Reference\/Reference.html\" target=\"_blank\">UICollectionView<\/a>, since only the latter has been adapted by Apple for the <strong><a title=\"UIDynamicAnimator\" href=\"https:\/\/developer.apple.com\/library\/ios\/documentation\/UIKit\/Reference\/UIDynamicAnimator_Class\/Reference\/Reference.html\" target=\"_blank\">UIDynamicAnimator <\/a><\/strong>animation object. <strong>&nbsp;<\/strong><strong><\/strong><\/p>\n<p style=\"text-align: center\"><a href=\"http:\/\/blog.denivip.ru\/wp-content\/uploads\/2013\/10\/iOS-7-Messages-005.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-4969 aligncenter\" alt=\"\" src=\"http:\/\/blog.denivip.ru\/wp-content\/uploads\/2013\/10\/iOS-7-Messages-005-300x205.jpg\" width=\"300\" height=\"205\" srcset=\"http:\/\/blog.denivip.ru\/wp-content\/uploads\/2013\/10\/iOS-7-Messages-005-300x205.jpg 300w, http:\/\/blog.denivip.ru\/wp-content\/uploads\/2013\/10\/iOS-7-Messages-005.jpg 973w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>After that, we revised the standard <a title=\"UICollectionViewFlowLayout\" href=\"https:\/\/developer.apple.com\/library\/ios\/documentation\/uikit\/reference\/UICollectionViewFlowLayout_class\/Reference\/Reference.html\" target=\"_blank\">UICollectionViewFlowLayout<\/a> header file:<\/p>\n<p>[gist id= 7153677 file=DVCollectionViewFlowLayout.h] <\/p>\n<p>by defining the UIDynamicAnimator object<strong>&nbsp;<\/strong> and overriding the functions involved:<\/p>\n<p>[gist id= 7153677 file=DVCollectionViewFlowLayout.m] <\/p>\n<p>Dynamic behaviour activates when you add it to the animator object, an instance of <strong>UIDynamicAnimator.<\/strong> The Animator defines the context of dynamic behaviour.<\/p>\n<p>The UIAttachmentBehavior object defines relationship between the dynamic element of the UICollectionViewLayoutAttributes class and the item.center point.<br \/>\nWhen the point moves, the element associated with it also moves. Using such properties as <i>length<\/i>, <i>damping<\/i> and <i>frequency<\/i>, you can easily customize behaviour.<\/p>\n<p>[gist id= 7153677 file= UIAttachmentBehavior]<\/p>\n<p>It is also important to properly choose resistanceFactor <\/p>\n<p>[gist id = 7153677 file = resistanceFactor]<\/p>\n<h3 align=\"JUSTIFY\"><\/h3>\n<h3>More on the topic:<\/h3>\n<ol>\n<li>\n<address><a title=\"Parallax in iOS applications\" href=\"http:\/\/blog.denivip.ru\/index.php\/2013\/07\/%d1%8d%d1%84%d1%84%d0%b5%d0%ba%d1%82-%d0%bf%d0%b0%d1%80%d0%b0%d0%bb%d0%bb%d0%b0%d0%ba%d1%81%d0%b0-%d0%b2-ios-%d0%bf%d1%80%d0%b8%d0%bb%d0%be%d0%b6%d0%b5%d0%bd%d0%b8%d1%8f%d1%85\/\" rel=\"bookmark\">Parallax in iOS applications<\/a><\/address>\n<\/li>\n<li>\n<address><a title=\"The Art of Core Motion in iOS\" href=\"http:\/\/blog.denivip.ru\/index.php\/2013\/07\/%d0%be%d1%81%d0%b2%d0%b0%d0%b8%d0%b2%d0%b0%d0%b5%d0%bc-core-motion-%d0%b2-ios\/\" rel=\"bookmark\">The Art of Core Motion in iOS<\/a><\/address>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the release of iOS 7 developers got empowered by many new tools to make fascinating effects and animations in their apps. However applicability of many of them is still in question. As soon as we made ourselves familiar with them, in our new project we decided to make a new animation, similar to that [&hellip;]<\/p>\n","protected":false},"author":25,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,407],"tags":[98,23,522,99,100,448,494,41],"_links":{"self":[{"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/posts\/5039"}],"collection":[{"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/comments?post=5039"}],"version-history":[{"count":2,"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/posts\/5039\/revisions"}],"predecessor-version":[{"id":5085,"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/posts\/5039\/revisions\/5085"}],"wp:attachment":[{"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/media?parent=5039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/categories?post=5039"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/tags?post=5039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}