<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Lorenzo Montenero on Medium]]></title>
        <description><![CDATA[Stories by Lorenzo Montenero on Medium]]></description>
        <link>https://medium.com/@lorenzomontenero?source=rss-412c81c9dbdf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*sPuwOqRSWFBwdA3S</url>
            <title>Stories by Lorenzo Montenero on Medium</title>
            <link>https://medium.com/@lorenzomontenero?source=rss-412c81c9dbdf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 22:27:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lorenzomontenero/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Folding animation using SwiftUI for Apple Watch]]></title>
            <link>https://medium.com/@lorenzomontenero/folding-animation-using-swiftui-for-apple-watch-d644090afd86?source=rss-412c81c9dbdf------2</link>
            <guid isPermaLink="false">https://medium.com/p/d644090afd86</guid>
            <category><![CDATA[apple-watch]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[folding-animation]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Lorenzo Montenero]]></dc:creator>
            <pubDate>Fri, 16 Jul 2021 16:11:51 GMT</pubDate>
            <atom:updated>2021-07-16T16:11:51.958Z</atom:updated>
            <content:encoded><![CDATA[<h3>Folding animation using SwiftUI</h3><h3>Folding animation using SwiftUI</h3><p>I searched on internet for a long time for something that could help me make an animation for my app, without finding anything, sadly.</p><p>The idea was to replicate the same dynamic as a Split-Flap display to use it as a scoreboard.</p><p>Do you know?<br>There are many ringed cards that individually represent half of a number.<br>Two of these cards together form a whole number and to score another point you need to flip a card up (or down). In any case, it is more complicated to describe it than to show it: this is what I was trying to achieve.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F7TxPL0gnDJA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D7TxPL0gnDJA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F7TxPL0gnDJA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f86a889180c530f8c73092eb21cb9a55/href">https://medium.com/media/f86a889180c530f8c73092eb21cb9a55/href</a></iframe><p>Let’s see how I made it! 🕺🏻</p><h4>Step 1- The structure</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a409f01ad298bc3df89b7e3134b16ddc/href">https://medium.com/media/a409f01ad298bc3df89b7e3134b16ddc/href</a></iframe><p>I used 2 ZStacks because I want the innermost one to rotate, while the external one remains stationary to act as the background of the animation.</p><p>SwiftUI does not easily allow you to round the individual corners of a View (Rectangle) so I had to add a struct and an extension at the end.</p><h4>Step 2- The counter</h4><p>Now that the structure is ready, let’s proceed by inserting the two labels. <br>We also declare 3 variables of type <a href="http://twitter.com/State">@State</a>. ‘Counter’ keeps the score,<br>‘ScrollAmount’ keeps the angle of rotation of the paper, ‘offset’ will be needed later to use the onDragGesture.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4fc894ef072734202630f35c2cd41a62/href">https://medium.com/media/4fc894ef072734202630f35c2cd41a62/href</a></iframe><p>As you can see I inserted two labels and not just one.<br>The first is visible during the rotation of the first card, after which, thanks to the ternary operator you see in the .opacity modifier, the second appears and the first disappears.</p><h4>Step 3- The logic</h4><p>Now we just have to add some logic to increase the ‘counter’ variable when the card completes half a turn (90 degrees). The remaining half is completed thanks to the withAnimate function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19a95892c60f52b21fd7e8a0239a0a49/href">https://medium.com/media/19a95892c60f52b21fd7e8a0239a0a49/href</a></iframe><p>Basically, I created the incrementAnimation() function which, based on the angle of the card, updates the counter. Then I called that function both in the .onTap event and in the .onDrag event. The same goes for the decrementAnimation() function which, however, is only called in the .onDrag event when a swipe of your finger upwards is recognized (See condition on line 85 self.offset.height &lt;0).</p><p>That’s all :)</p><p>I would like to thank Morena Pierro for inspiring me every time with her animations, we’ll soon release an app for Apple Watch make using of what I’ve shown to you.</p><p>See you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d644090afd86" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>