willowtreeapps / spruce-ios

Swift library for choreographing animations on the screen.
MIT License
3.44k stars 206 forks source link

Standar custom animation doesn't work #90

Closed iac0 closed 7 years ago

iac0 commented 7 years ago

Hi, i have downloaded the example app and i put as rootViewController of the window yours ExampleViewController where i put a simple square red view ( code above ). Nothings happen, why? ` import UIKit import Spruce

class ExampleViewController: UIViewController { let animations: [StockAnimation] var sortFunction: SortFunction? var animationView: UIView? = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) var timer: Timer?

init(animations: [StockAnimation], nibName: String?) {
    self.animations = [.fadeIn, .expand(.slightly)]

    animationView?.isUserInteractionEnabled = true
    super.init(nibName: nibName, bundle: nil)
    animationView?.backgroundColor = .red
    view.addSubview(animationView!)

    view.frame = UIScreen.main.bounds
    view.backgroundColor = .blue
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
    super.viewDidLoad()
    setup()

    let tapGesture = UITapGestureRecognizer(target: self, action: #selector(prepareAnimation))
    animationView?.addGestureRecognizer(tapGesture)
}

func setup() {

}

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    prepareAnimation()
}

func prepareAnimation() {
    animationView?.spruce.prepare(with: animations)

    timer?.invalidate()
    timer = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(callAnimation), userInfo: nil, repeats: false)
}

func callAnimation() {

    let animation = SpringAnimation(duration: 0.7)
    DispatchQueue.main.async {
        self.animationView?.spruce.animate(self.animations, animationType: animation)
    }
}

}`

jacksontaylor13 commented 7 years ago

@iac0 So I would need a tad bit more context on the setup of your view to see exactly why nothing is happening. But some suggestions to look for, is your red view inside of the animationView? This animationView is being told to animate all of the subviews. If there are no subviews of the animationView then nothing will happen. If that doesn't work then we can discuss more about the setup of your view layout to see if there is anything happening there.

jacksontaylor13 commented 7 years ago

@iac0 Any updates on this issue?

chrsmys commented 7 years ago

Hello @iac0 I am going to close this issue due to inactivity. If this was not resolved please feel free to open a new issue. Thanks!