

{"id":2062,"date":"2016-09-15T18:03:24","date_gmt":"2016-09-15T15:03:24","guid":{"rendered":"https:\/\/tubikstudio.com\/?p=2062"},"modified":"2023-08-16T09:25:48","modified_gmt":"2023-08-16T09:25:48","slug":"case-study-squeezeoutswitch-animation-in-code","status":"publish","type":"post","link":"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/","title":{"rendered":"Case Study: SqueezeOutSwitch. Animation in Code"},"content":{"rendered":"<p><span style=\"color: #333333;\">UI animation has been the subject of hot debates for a long time. Designers work over the sophisticated animations to make interfaces attractive, original and functional while developers often support the idea that slick and complex animation takes more effort in the process of development than necessary.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #333333;\">As you know from our previous posts devoted to the issues of interface animation, here in Tubik we support the position that wisely used animation is the powerful and multi-functional tool enhancing user experience. We checked that on numerous design projects for diverse purposes. Our complex motion design concepts have been used by developers who like challenges and want to present high-level skills in coding.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #333333;\">Broadening our professional horizons, we also started sharing our design concepts on GitHub, to show how design, even quite complex and specific, can be brought to life with code. Today we will look at more detail at <a style=\"color: #333333;\" href=\"https:\/\/github.com\/tubikstudio\/SqueezeOutSwitch\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">SqueezeOut Switch animation<\/a> of the interface interaction.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #333333;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1101\" src=\"https:\/\/blog.tubikstudio.com\/wp-content\/uploads\/2015\/12\/button-animation-tubik-1.gif\" alt=\"button animation tubik\" width=\"800\" height=\"600\" \/><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #333333;\">The design concept <a style=\"color: #333333;\" href=\"https:\/\/dribbble.com\/shots\/2237700-Switch-Control-Animation\" target=\"_blank\" rel=\"noopener noreferrer\">Switch Control Animation<\/a>\u00a0was presented on Dribbble featuring animated switch control that can be used for accepting or declining the changes on any settings screen. The main motion design style the designer aimed at was adding some gum effect when the control is switched on and off. And this sort of design details can become a bit of challenge for developers.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #333333;\">The animation in code representation is made of two parts.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #333333;\">The first part works like that: when a user makes a tap on the screen, the circle has to move to the opposite side until it is covered by the baffler. Then animation slightly slows down, the circle changes its appearance, goes up to the final point and features bouncing. The baffler also shows the animated pulsing with the circle. The oscillations decay.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #333333;\">The second variant takes place when a user tries to move the circle manually, like pressing it and pulls to the needed side and then can release. While the user pulls the circle, it changes its position within an acceptable range, up to maximum stretching of the baffler. The baffler stretches only to one side in that case. If the user releases the circle not taking him to the middle of the switcher, it gets back to its initial position and pulses. The baffler will just get back to the initial point. If the user takes the circle further than the middle of the switch, it goes to the opposite side, both the circle and baffler pulsing, and the circle changing its image.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #333333;\">Animation of the circle movement doesn&#8217;t create any problems. This is the standard task which can be solved with UIView animation and CASpringAnimation. However, animation of the baffler is more challenging.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #333333;\">In the case when animation is done with Core Animation, setting the initial and final path, then the arc performance is unpredictable. In addition, the form of animation can be inappropriate and the problems with color change can raise.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #333333;\">In animation, the change should be done discretely. When should it be done? If you do it in advance, then the good point is when path is at its initial stage, which means it features the straight line in the middle of switch. So, you have to create an array with the set of paths and colors and place it into CAKeyframeAnimation. The approach gives the working outcome, still the code will look messy and illegible. Moreover, the circle will need to be moved manually for synchronization.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #333333;\">In this case we can use CADisplayLink (timer of screen redrawing) and manipulate with presentationLayer (the copy of the layer which is visible on the screen at the moment). In the method launching CADisplayLink, we will change the path for the buffler. The points which form this path depend on the position of the circle in the switcher. The position of the circle is animated with UIView animation. Therefore, animation with UIView will smoothly change the bearings of the circle layer, while we are changing the path of the buffler on the basis of those bearings.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #333333;\">The path for the buffler feature two UIBeziePaths.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2069\" src=\"https:\/\/blog.tubikstudio.com\/wp-content\/uploads\/2016\/09\/UI-animation-code-1.jpg\" alt=\"UI animation code\" width=\"1000\" height=\"702\" srcset=\"https:\/\/blog.tubikstudio.com\/wp-content\/uploads\/2016\/09\/UI-animation-code-1.jpg 1000w, https:\/\/blog.tubikstudio.com\/wp-content\/uploads\/2016\/09\/UI-animation-code-1-300x211.jpg 300w, https:\/\/blog.tubikstudio.com\/wp-content\/uploads\/2016\/09\/UI-animation-code-1-768x539.jpg 768w, https:\/\/blog.tubikstudio.com\/wp-content\/uploads\/2016\/09\/UI-animation-code-1-150x105.jpg 150w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #333333;\">The first one goes from the point 1 to the middle of the circle edge at point 3. Control point for this curve is point 2, it proportionally depends on how far the circle moved out. The second line goes from point 3 to point 5 and its control point is point 4. In this way we can get the line of the buffler edge smoother.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #333333;\">The method of forming path for the particular extreme point<\/span><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><script src=\"https:\/\/gist.github.com\/tubikstudio\/be382384fc30497be99c7747f2b55153.js\"><\/script><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #333333;\">The method of animation on tap \u00a0<\/span><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #333333;\"><script src=\"https:\/\/gist.github.com\/tubikstudio\/eb5a883c7c1a5e74e5d2baf01c051a78.js\"><\/script><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #333333;\">For reaction on pan we added UIPanGestureRecognizer. Here is the method that processes it<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #333333;\"><script src=\"https:\/\/gist.github.com\/tubikstudio\/09fea70afdb1b359a4f0c96ef85377d3.js\"><\/script><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #333333;\">Welcome to review the <a style=\"color: #333333;\" href=\"https:\/\/github.com\/tubikstudio\/SqueezeOutSwitch\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">GitHub source code<\/a> for this animation. New cases are coming soon!<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Practical case presenting the detailed description of coded UI animation for switch control concept. Tips on developing specific animated design effects.<\/p>\n","protected":false},"author":3,"featured_media":5998,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[4,7,9],"tags":[20,502,208,515,233,269,270,271,272,275,319,325,336,447,457,479,482,491],"coauthors":[],"class_list":["post-2062","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-case_study","category-processes_and_tools","category-ui_ux","tag-app-design","tag-ux","tag-github","tag-uxui","tag-human-computer-interaction","tag-ios-animation","tag-ios-animation-case-study","tag-ios-best-practices","tag-ios-developers","tag-ios-development-case-study","tag-mobile-app","tag-mobile-development","tag-motion-design","tag-tubik-studio","tag-ui","tag-usability","tag-user-experience","tag-user-interface"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Case Study: SqueezeOutSwitch. Animation in Code<\/title>\n<meta name=\"description\" content=\"Practical case presenting the detailed description of coded UI animation for switch control concept. Tips on developing specific animated design effects.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Case Study: SqueezeOutSwitch. Animation in Code\" \/>\n<meta property=\"og:description\" content=\"Practical case presenting the detailed description of coded UI animation for switch control concept. Tips on developing specific animated design effects.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Tubik Blog: Articles About Design\" \/>\n<meta property=\"article:published_time\" content=\"2016-09-15T15:03:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-16T09:25:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/blog.tubikstudio.com\/wp-content\/uploads\/2016\/09\/Tubik-Studio-iOS-development.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"797\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Marina Yalanska\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Marina Yalanska\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/\",\"url\":\"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/\",\"name\":\"Case Study: SqueezeOutSwitch. Animation in Code\",\"isPartOf\":{\"@id\":\"https:\/\/tubikstudio.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/blog.tubikstudio.com\/wp-content\/uploads\/2016\/09\/Tubik-Studio-iOS-development.jpg\",\"datePublished\":\"2016-09-15T15:03:24+00:00\",\"dateModified\":\"2023-08-16T09:25:48+00:00\",\"author\":{\"@id\":\"https:\/\/tubikstudio.com\/blog\/#\/schema\/person\/320206b0076eb11ea0c0d4d17012c36f\"},\"description\":\"Practical case presenting the detailed description of coded UI animation for switch control concept. Tips on developing specific animated design effects.\",\"breadcrumb\":{\"@id\":\"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/#primaryimage\",\"url\":\"https:\/\/blog.tubikstudio.com\/wp-content\/uploads\/2016\/09\/Tubik-Studio-iOS-development.jpg\",\"contentUrl\":\"https:\/\/blog.tubikstudio.com\/wp-content\/uploads\/2016\/09\/Tubik-Studio-iOS-development.jpg\",\"width\":1200,\"height\":797,\"caption\":\"Tubik Studio iOS development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tubikstudio.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Case Study: SqueezeOutSwitch. Animation in Code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tubikstudio.com\/blog\/#website\",\"url\":\"https:\/\/tubikstudio.com\/blog\/\",\"name\":\"Tubik Blog: Articles About Design\",\"description\":\"Tubik Studio\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tubikstudio.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/tubikstudio.com\/blog\/#\/schema\/person\/320206b0076eb11ea0c0d4d17012c36f\",\"name\":\"Marina Yalanska\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tubikstudio.com\/blog\/#\/schema\/person\/image\/2ddde1c118fcf989ce8e73997a3909dd\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/630af235953a586b42ed17f9ea472b131bcde00719efc655984d63ca2078e7a2?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/630af235953a586b42ed17f9ea472b131bcde00719efc655984d63ca2078e7a2?s=96&d=mm&r=g\",\"caption\":\"Marina Yalanska\"},\"url\":\"https:\/\/tubikstudio.com\/blog\/author\/marina-yalanska\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Case Study: SqueezeOutSwitch. Animation in Code","description":"Practical case presenting the detailed description of coded UI animation for switch control concept. Tips on developing specific animated design effects.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/","og_locale":"en_US","og_type":"article","og_title":"Case Study: SqueezeOutSwitch. Animation in Code","og_description":"Practical case presenting the detailed description of coded UI animation for switch control concept. Tips on developing specific animated design effects.","og_url":"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/","og_site_name":"Tubik Blog: Articles About Design","article_published_time":"2016-09-15T15:03:24+00:00","article_modified_time":"2023-08-16T09:25:48+00:00","og_image":[{"width":1200,"height":797,"url":"https:\/\/blog.tubikstudio.com\/wp-content\/uploads\/2016\/09\/Tubik-Studio-iOS-development.jpg","type":"image\/jpeg"}],"author":"Marina Yalanska","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Marina Yalanska","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/","url":"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/","name":"Case Study: SqueezeOutSwitch. Animation in Code","isPartOf":{"@id":"https:\/\/tubikstudio.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/#primaryimage"},"image":{"@id":"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/#primaryimage"},"thumbnailUrl":"https:\/\/blog.tubikstudio.com\/wp-content\/uploads\/2016\/09\/Tubik-Studio-iOS-development.jpg","datePublished":"2016-09-15T15:03:24+00:00","dateModified":"2023-08-16T09:25:48+00:00","author":{"@id":"https:\/\/tubikstudio.com\/blog\/#\/schema\/person\/320206b0076eb11ea0c0d4d17012c36f"},"description":"Practical case presenting the detailed description of coded UI animation for switch control concept. Tips on developing specific animated design effects.","breadcrumb":{"@id":"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/#primaryimage","url":"https:\/\/blog.tubikstudio.com\/wp-content\/uploads\/2016\/09\/Tubik-Studio-iOS-development.jpg","contentUrl":"https:\/\/blog.tubikstudio.com\/wp-content\/uploads\/2016\/09\/Tubik-Studio-iOS-development.jpg","width":1200,"height":797,"caption":"Tubik Studio iOS development"},{"@type":"BreadcrumbList","@id":"https:\/\/tubikstudio.com\/blog\/case-study-squeezeoutswitch-animation-in-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tubikstudio.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Case Study: SqueezeOutSwitch. Animation in Code"}]},{"@type":"WebSite","@id":"https:\/\/tubikstudio.com\/blog\/#website","url":"https:\/\/tubikstudio.com\/blog\/","name":"Tubik Blog: Articles About Design","description":"Tubik Studio","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tubikstudio.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/tubikstudio.com\/blog\/#\/schema\/person\/320206b0076eb11ea0c0d4d17012c36f","name":"Marina Yalanska","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tubikstudio.com\/blog\/#\/schema\/person\/image\/2ddde1c118fcf989ce8e73997a3909dd","url":"https:\/\/secure.gravatar.com\/avatar\/630af235953a586b42ed17f9ea472b131bcde00719efc655984d63ca2078e7a2?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/630af235953a586b42ed17f9ea472b131bcde00719efc655984d63ca2078e7a2?s=96&d=mm&r=g","caption":"Marina Yalanska"},"url":"https:\/\/tubikstudio.com\/blog\/author\/marina-yalanska\/"}]}},"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/tubikstudio.com\/blog\/wp-json\/wp\/v2\/posts\/2062","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tubikstudio.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tubikstudio.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tubikstudio.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/tubikstudio.com\/blog\/wp-json\/wp\/v2\/comments?post=2062"}],"version-history":[{"count":3,"href":"https:\/\/tubikstudio.com\/blog\/wp-json\/wp\/v2\/posts\/2062\/revisions"}],"predecessor-version":[{"id":14692,"href":"https:\/\/tubikstudio.com\/blog\/wp-json\/wp\/v2\/posts\/2062\/revisions\/14692"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tubikstudio.com\/blog\/wp-json\/wp\/v2\/media\/5998"}],"wp:attachment":[{"href":"https:\/\/tubikstudio.com\/blog\/wp-json\/wp\/v2\/media?parent=2062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tubikstudio.com\/blog\/wp-json\/wp\/v2\/categories?post=2062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tubikstudio.com\/blog\/wp-json\/wp\/v2\/tags?post=2062"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/tubikstudio.com\/blog\/wp-json\/wp\/v2\/coauthors?post=2062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}