Code Monkey home page Code Monkey logo

Comments (4)

Narayane avatar Narayane commented on August 15, 2024 1

Potentially. I'll keep you in touch :)

from viewanimator.

marcosgriselli avatar marcosgriselli commented on August 15, 2024

@Narayane I was thinking about that feature some time ago. We currently support springs but supporting timing functions shouldn't be much work. Do you want to take a shot at it? I can help out with the PR.

from viewanimator.

Narayane avatar Narayane commented on August 15, 2024

Hi @marcosgriselli,

I've tried to follow this approach but it doesn't work with your extension UIView.animate()...

Even when I add parameter options: [.curveEaseInOut] to your extension UIView.animate(), it doesn't seem to be taken into account at runtime: move is the save with and without it...

let fromAnimation = AnimationType.from(direction: .bottom, offset: 270)
UIView.animate(views: [self.myView], animations: [fromAnimation], delay: 0, duration: 1, options: [.curveEaseInOut])

Do you have any idea on how to make it?

Thanks.

from viewanimator.

marcosgriselli avatar marcosgriselli commented on August 15, 2024

@Narayane the reason why the options don't work on that particular function is that the library is using the UIView springs animation API. We need to create a new function that uses the UIView animation API that doesn't use springs.

Here's what the function will look like:

 static func animate(views: [UIView],
                    animations: [Animation],
                    reversed: Bool = false,
                    initialAlpha: CGFloat = 0.0,
                    finalAlpha: CGFloat = 1.0,
                    delay: Double = 0,
                    animationInterval: TimeInterval = 0.05,
                    duration: TimeInterval = ViewAnimatorConfig.duration,
                    options: UIView.AnimationOptions = [],
                    completion: (() -> Void)? = nil) {
    
    guard views.count > 0 else {
        completion?()
        return
    }
    
    views.forEach { $0.alpha = initialAlpha }
    let dispatchGroup = DispatchGroup()
    for _ in 1...views.count { dispatchGroup.enter() }
    DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
        for (index, view) in views.enumerated() {
            view.alpha = initialAlpha
            view.animate(animations: animations,
                         reversed: reversed,
                         initialAlpha: initialAlpha,
                         finalAlpha: finalAlpha,
                         delay: Double(index) * animationInterval,
                         duration: duration,
                         options: options,
                         completion: { dispatchGroup.leave() })
        }
    }
    
    dispatchGroup.notify(queue: .main) {
        completion?()
    }
}

I'll create a release later this week with support for this but for the moment that function should be enough to drop-in and use in your project.

from viewanimator.

Related Issues (20)

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.