Rupert  Beatty

Rupert Beatty

1666168920

Advance: Physics-based animations for iOS, tvOS, and macOS

Advance

An animation library for iOS, tvOS, and macOS that uses physics-based animations (including springs) to power interactions that move and respond realistically.

let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))

// Springs animate changes to a value
let spring = Spring(initialValue: view.center)

// The `onChange` closure will be called every time the spring updates
spring.onChange = { [view] newCenter in
    view.center = newCenter
}

/// The view's center will realistically animate to the new target value.
spring.target = CGPoint(x: 300, y: 200)

Installation

There are several ways to integrate Advance into your project.

Manually: add Advance.xcodeproj to your project, then add Advance-{iOS|macOS|tvOS}.framework as an "Embedded Binary" to your application target (under General in target settings). From there, add import Advance to your code and you're good to go.

Carthage: add github "timdonnelly/Advance" to your Cartfile.

CocoaPods: add pod 'Advance' to your Podfile.

Swift Package Manager: add a dependency to your Project.swift: .package(url: "http://github.com/timdonnelly/Advance", from: "3.0.0")

Requirements

  • iOS 10+, tvOS 10+, or macOS 10.12+
  • Swift 5.0 (Xcode 10.2 or higher)

Usage

API documentation is available here.

Advance animations are applied on every frame (using CADisplayLink on iOS/tvOS, and CVDisplayLink on macOS), allowing for fine-grained control at any time.

Spring

Spring instances animate changes to a value over time, using spring physics.

let spring = Spring(initialValue: 0.0)
spring.onChange = { [view] newAlpha in 
    view.alpha = newAlpha 
}

// Off it goes!
spring.target = 0.5

Configuring a spring


/// Spring values can be adjusted at any time.
spring.tension = 30.0 /// The strength of the spring
spring.damping = 2.0 /// The resistance (drag) that the spring encounters
spring.threshold = 0.1 /// The maximum delta between the current value and the spring's target (for each component) for which the simulation can enter a converged state.

/// Update the simulation state at any time.
spring.velocity = 6.5
spring.value = 0.2

/// Sets the spring's target and the current simulation value, and removes all velocity. This causes the spring to converge at the given value.
spring.reset(to: 0.5)

Animator

Animator allows for more flexibility in the types of animation that can be performed, but gives up some convenience in order to do so. Specifically, animators allow for any type of animation or simulation to be performed for a single value.

let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))

/// Animators coordinate animations to drive changes to a value.
let sizeAnimator = Animator(initialValue: view.bounds.size)

sizeAnimator.onChange = { [view] newSize in
    view.bounds.size = newSize
}

/// A simple timed animation
sizeAnimator.animate(to: CGSize(width: 123, height: 456), duration: 0.25, timingFunction: .easeInOut)

/// Some time in the future (before the previous timed animation was complete)...

/// Spring physics will move the view's size to the new value, maintaining the velocity from the timed animation.
sizeAnimator.simulate(using: SpringFunction(target: CGSize(width: 300, height: 300)))

/// Some time in the future (before the previous spring animation was complete)...

/// The value will keep the same velocity that it had from the preceeding spring
/// animation, and a decay function will slowly bring movement to a stop.
sizeAnimator.simulate(using: DecayFunction(drag: 2.0))

Animators support two fundamentally different types of animations: timed and simulated.

Timed animations

Timed animations are, well, timed: they have a fixed duration, and they animate to a final value in a predictable manner.

animator.animate(to: CGSize(width: 123, height: 456), duration: 0.25, timingFunction: .easeInOut)

TimingFunction described the pacing of a timed animation.

TimingFunction comes with a standard set of functions:

TimingFunction.linear // No easing
TimingFunction.easeIn
TimingFunction.easeOut
TimingFunction.easeInOut
TimingFunction.swiftOut // Similar to Material Design's default curve

Custom timing functions can be expressed as unit beziers (described here).

let customTimingFunction = TimingFunction(x1: 0.1, y1: 0.2, x2: 0.6, y2: 0.0)

Simulated animations

Simulated animations use a simulation function to power a physics-based transition. Simulation functions are types conforming to the SimulationFunction protocol.

Simulated animations may be started using two different methods:

// Begins animating with the custom simulation function, maintaining the previous velocity of the animator.
animator.simulate(using: MyCustomFunction())

// or...

// Begins animating with the custom simulation function, imparting the specified velocity into the simulation.
animator.simulate(using: DecayFunction(), initialVelocity: dragGestureRecognizer.velocity(in: view))

Animating Custom Types

Values conforming to the VectorConvertible protocol can be animated by Advance. Conforming types can be converted to and from a Vector implementation.

public protocol VectorConvertible: Equatable, Interpolatable {
    associatedtype VectorType: SIMD where VectorType.Scalar == Double
    init(vector: VectorType)
    var vector: VectorType { get }
}

The library adds conformance for many common types through extensions.

Contributing

If you encounter any issues or surprises, please open an issue.

For suggestions or new features, please consider opening a PR with a functional implementation. Issues may be used if you aren't sure how to implement the change, but working code is typically easier to evaluate.

Download Details:

Author: Timdonnelly
Source Code: https://github.com/timdonnelly/Advance 
License: BSD-2-Clause license

#swift #ios #animation #physics 

What is GEEK

Buddha Community

Advance: Physics-based animations for iOS, tvOS, and macOS
Rupert  Beatty

Rupert Beatty

1666168920

Advance: Physics-based animations for iOS, tvOS, and macOS

Advance

An animation library for iOS, tvOS, and macOS that uses physics-based animations (including springs) to power interactions that move and respond realistically.

let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))

// Springs animate changes to a value
let spring = Spring(initialValue: view.center)

// The `onChange` closure will be called every time the spring updates
spring.onChange = { [view] newCenter in
    view.center = newCenter
}

/// The view's center will realistically animate to the new target value.
spring.target = CGPoint(x: 300, y: 200)

Installation

There are several ways to integrate Advance into your project.

Manually: add Advance.xcodeproj to your project, then add Advance-{iOS|macOS|tvOS}.framework as an "Embedded Binary" to your application target (under General in target settings). From there, add import Advance to your code and you're good to go.

Carthage: add github "timdonnelly/Advance" to your Cartfile.

CocoaPods: add pod 'Advance' to your Podfile.

Swift Package Manager: add a dependency to your Project.swift: .package(url: "http://github.com/timdonnelly/Advance", from: "3.0.0")

Requirements

  • iOS 10+, tvOS 10+, or macOS 10.12+
  • Swift 5.0 (Xcode 10.2 or higher)

Usage

API documentation is available here.

Advance animations are applied on every frame (using CADisplayLink on iOS/tvOS, and CVDisplayLink on macOS), allowing for fine-grained control at any time.

Spring

Spring instances animate changes to a value over time, using spring physics.

let spring = Spring(initialValue: 0.0)
spring.onChange = { [view] newAlpha in 
    view.alpha = newAlpha 
}

// Off it goes!
spring.target = 0.5

Configuring a spring


/// Spring values can be adjusted at any time.
spring.tension = 30.0 /// The strength of the spring
spring.damping = 2.0 /// The resistance (drag) that the spring encounters
spring.threshold = 0.1 /// The maximum delta between the current value and the spring's target (for each component) for which the simulation can enter a converged state.

/// Update the simulation state at any time.
spring.velocity = 6.5
spring.value = 0.2

/// Sets the spring's target and the current simulation value, and removes all velocity. This causes the spring to converge at the given value.
spring.reset(to: 0.5)

Animator

Animator allows for more flexibility in the types of animation that can be performed, but gives up some convenience in order to do so. Specifically, animators allow for any type of animation or simulation to be performed for a single value.

let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))

/// Animators coordinate animations to drive changes to a value.
let sizeAnimator = Animator(initialValue: view.bounds.size)

sizeAnimator.onChange = { [view] newSize in
    view.bounds.size = newSize
}

/// A simple timed animation
sizeAnimator.animate(to: CGSize(width: 123, height: 456), duration: 0.25, timingFunction: .easeInOut)

/// Some time in the future (before the previous timed animation was complete)...

/// Spring physics will move the view's size to the new value, maintaining the velocity from the timed animation.
sizeAnimator.simulate(using: SpringFunction(target: CGSize(width: 300, height: 300)))

/// Some time in the future (before the previous spring animation was complete)...

/// The value will keep the same velocity that it had from the preceeding spring
/// animation, and a decay function will slowly bring movement to a stop.
sizeAnimator.simulate(using: DecayFunction(drag: 2.0))

Animators support two fundamentally different types of animations: timed and simulated.

Timed animations

Timed animations are, well, timed: they have a fixed duration, and they animate to a final value in a predictable manner.

animator.animate(to: CGSize(width: 123, height: 456), duration: 0.25, timingFunction: .easeInOut)

TimingFunction described the pacing of a timed animation.

TimingFunction comes with a standard set of functions:

TimingFunction.linear // No easing
TimingFunction.easeIn
TimingFunction.easeOut
TimingFunction.easeInOut
TimingFunction.swiftOut // Similar to Material Design's default curve

Custom timing functions can be expressed as unit beziers (described here).

let customTimingFunction = TimingFunction(x1: 0.1, y1: 0.2, x2: 0.6, y2: 0.0)

Simulated animations

Simulated animations use a simulation function to power a physics-based transition. Simulation functions are types conforming to the SimulationFunction protocol.

Simulated animations may be started using two different methods:

// Begins animating with the custom simulation function, maintaining the previous velocity of the animator.
animator.simulate(using: MyCustomFunction())

// or...

// Begins animating with the custom simulation function, imparting the specified velocity into the simulation.
animator.simulate(using: DecayFunction(), initialVelocity: dragGestureRecognizer.velocity(in: view))

Animating Custom Types

Values conforming to the VectorConvertible protocol can be animated by Advance. Conforming types can be converted to and from a Vector implementation.

public protocol VectorConvertible: Equatable, Interpolatable {
    associatedtype VectorType: SIMD where VectorType.Scalar == Double
    init(vector: VectorType)
    var vector: VectorType { get }
}

The library adds conformance for many common types through extensions.

Contributing

If you encounter any issues or surprises, please open an issue.

For suggestions or new features, please consider opening a PR with a functional implementation. Issues may be used if you aren't sure how to implement the change, but working code is typically easier to evaluate.

Download Details:

Author: Timdonnelly
Source Code: https://github.com/timdonnelly/Advance 
License: BSD-2-Clause license

#swift #ios #animation #physics 

iOS App Development Company in Singapore

iOS app development in Singapore

iOS has become the first priority for most smartphone users because of the security it offers compares to the Android operating system. Due to this reason, it is suggested to launch an app in iOS before other platforms.

Want to develop an iOS app in Singapore?

WebClues Infotech with its worldwide reach has already offered its iOS app development services to customers in Singapore. With a highly-skilled development team of 120+ members, WebClues Infotech has got the required resources an agency needs to fulfil client requirements around the world.

Want to know more about our iOS app development services in Singapore?

Visit: https://www.webcluesinfotech.com/iphone-app-development/

Share your requirements https://www.webcluesinfotech.com/contact-us/

View Portfolio https://www.webcluesinfotech.com/portfolio/

#ios app development in singapore #ios app development company #ios app development #ios #ios app #hire ios developer

iOS App Development in the United Arab Emirates

iOS App Development in the United Arab Emirates

Developed and Developing nations have seen a rapid rise in the demand for iOS app development and the United Arab Emirates is no exception. The use of on-demand apps has increased drastically in the last decade and business is leveraging this demand with launching iOS mobile apps.

Want to develop the iOS app in the United Arab Emirates?

WebClues Infotech after serving multiple clients in UAE has become well aware of the people’s needs in the region. With a highly experienced development team that has completed more than 950+ projects, we are prepared to serve you with your iOS app development needs.

Want to know more about our iOS App Development Services in UAE?

Visit: https://www.webcluesinfotech.com/iphone-app-development/

Share your requirements https://www.webcluesinfotech.com/contact-us/

View Portfolio https://www.webcluesinfotech.com/portfolio/

#ios app development in the united arab emirates #ios app development #ios app #ios #ios app development company #hire ios developer

iOS App Development Agency in the USA

iOS App Development Agency in the USA

Whenever a start-up in the USA launch an MVP version of the app they prefer to launch it only for iPhone user because the US has a large market of iPhone users in comparison to Android. The recent phenomenon of Clubhouse is the biggest example.

Want to develop an iOS app in the USA?

With 2 office locations across the USA and 6 worldwide, WebClues Infotech has the experience of serving a huge client base of 600+. After such a satisfied client base, WebClues Infotech is prepared to serve you with and iOS App Development Services in the USA.

Want to know more about our iOS App Development Services in the USA?

Visit: https://www.webcluesinfotech.com/iphone-app-development/

Share your requirements https://www.webcluesinfotech.com/contact-us/

View Portfolio https://www.webcluesinfotech.com/portfolio/

#ios app development agency in the usa #ios app development agency #ios app development #ios app #ios #hire ios app developer

iOS App Development Company in India

iOS app development company in India

India is considered the IT hub of the world because of n number of IT infrastructure development services offering companies. In this whole market iOS app development is the leading service offered by agencies across India

Want to develop the iOS app in India

WebClues Infotech with its head office in India has created a huge presence across the world over time and has served clients in all of the major countries around the world. WebClues Infotech with a highly skilled development team of 120+ members can help you deliver a better result at a reasonable cost.

Want to know more about our iOS app development services in India?

Visit: https://www.webcluesinfotech.com/iphone-app-development/

Share your requirements https://www.webcluesinfotech.com/contact-us/

View Portfolio https://www.webcluesinfotech.com/portfolio/

#ios app development company in india #ios app development company #ios app development #ios app #ios #hire ios app developer