Giter Site home page Giter Site logo

viewexperiments's Introduction

ViewExperiments

Rubber band effect?

I tried out this just for fun, and then I realized I need to add some words on how does this work. Here it goes.

What is a mask? What does that do?

If you create a mask and put it on the view, the masked area only is visible. Why does this fact matter? I will create a shapelayer of the size of the rectangle, only one of the edge is a curved path. The masked view will look like that.

What if that shape layer is updated in response to the gesture in real time? What does that look like? It will create an effect that acts as if a rubber band is stretched and back.

What is a curve made of? How does the given pan gesture data lead to drawing the curve?

What do I need to know to draw up the curve programmatically?

A curve is made of startpoint, endpoint, controlpoint.With these three parameters, you can create a UIBezierPath instance. For implementation purpose, I defined control value(normalized value), curve size to interpret the controlpoint. Also, I defined curve direction. By this I mean the direction that the curve forms from the view frame.

There’s gotta be a way to know which direction the user is panning off from the view so that the curve parameters(curve size, control value) are read correctly. There’s a long way to go from the pan gesture recognition to updating the mask. Each step and task that takes place in it is individual and independent to each other so that each task is taken for being fully tested programmatically. In a simpler form, it takes these three steps and I can accomplish the rubber band stretch effect.

How do I accomplish the snapping back animation when the pan gesture ends?

By constantly redrawing the path following the dragged gesture point; renewing the mask; I can accomplish the rubber band effect. And, as I drop the tap off from the display, I want it the curve to snap back with a nice spring animation. How do I do that? Given that spring animation doesn’t support path-based animation, I need to create a bunch of path and make a sort of a key frame animation so that the curve looks like it’s springing back to where it was before the pan gesture had begun. The control point overshoots the mid point of the startpoint and endpoint with smaller size. It overshoots over and over until it is halted.

For example, it starts with control point c1. It overshoots to c2, and then c3, c4, c5. I created (c1,c2,c3,c4,c5) from the given c1. And, given (c1,c2,c3,c4,c5), I created five paths, and then five animations. I chained them together so that it makes one big animation. The result is the above gjf as you see.

viewexperiments's People

Contributors

pearl7721user1 avatar

Watchers

James Cloos avatar  avatar

viewexperiments's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.