Code Monkey home page Code Monkey logo

animatordemo's Introduction

AnimatorDemo

以前,假设我们想在视图大小之前添加淡入,之后加入淡出,我们必须编写如下内容:

UIView.animate(withDuration: duration, animations: {
view.alpha = 1
}) { (_) in
UIView.animate(withDuration: self.duration, animations: {
view.bounds.size = CGSize(width: 200, height: 200)
view.frame.origin = CGPoint(x: 0, y: 100)
}, completion: { (_) in
UIView.animate(withDuration: self.duration, animations: {
view.alpha = 0
}, completion: nil)
})
}

现在,我们用声明式的API

view.animate([
.fadeIn(),
.resize(to: CGSize(width: 200, height: 200)),
.fadeOut()
])

之前我们想在view1动画结束后,执行view2的动画,代码如下:

UIView.animate(withDuration: duration, animations: {
view1.frame = CGRect(x: 200, y: 100, width: 70, height: 200)
}) { _ in
UIView.animate(withDuration: self.duration, animations: {
view1.alpha = 0
}, completion: { _ in
UIView.animate(withDuration: self.duration, animations: {
view2.frame = CGRect(x: 200, y: 300, width: 30, height: 250)
}, completion: { _ in
UIView.animate(withDuration: self.duration, animations: {
view2.alpha = 0
}, completion: nil)
})
})
}

现在:

Animator.animation(
view1.animate(
.custom(duration: duration, closure: { $0.frame = CGRect(x: 200, y: 100, width: 70, height: 200) }),
.fadeOut(duration)
),
view2.animate(
.custom(duration: duration, closure: { $0.frame = CGRect(x: 200, y: 300, width: 30, height: 250) }),
.fadeOut(duration)
)
)

image

animatordemo's People

Contributors

lzright123 avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

aichiko0225

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.