Gravity is a simple Swift Package Manager to add gravity to UI objects easily.

Last update: Nov 23, 2021

Gravity

--

Gravity is a simple Swift Package to add gravity to UI objects easily.

--

How to use:

Add a new Swift Package from XCode and paste the url of this repository (https://github.com/elpsk/Gravity).

Next, import the SDK:

import GravitySPM

Add your IBOutlets or your custom views:

@IBOutlet weak var label1: UILabel!
@IBOutlet weak var label2: UILabel!
@IBOutlet weak var button1: UIButton!
@IBOutlet weak var button2: UIButton!
@IBOutlet weak var switch1: UISwitch!
@IBOutlet weak var switch2: UISwitch!

var gravity: Gravity?

Next, attach your desidered items to a new UIDynamicItem array:

let gravityItems: [UIDynamicItem] = [
	label1, label2, button1, button2, switch1, switch2
]

and create a new Gravity object with desidered params:

gravity = Gravity(
    gravityItems: gravityItems,
    collisionItems: nil,
    referenceView: self.view,
    boundary: UIBezierPath(rect: self.view.frame),
    queue: nil)

Now you're ready to enable() or disable() the behavior.

@IBAction func didEnablePressed(_ sender: Any) {
    gravity?.enable()
}

@IBAction func didDisablePressed(_ sender: Any) {
    gravity?.disable()
}

Have fun.

--

Detailed info here: https://www.albertopasca.it/whiletrue/swift-have-fun-with-gravitybehavior-and-dynamicanimator/ or here.

GitHub

https://github.com/elpsk/Gravity
You might also like...

Easily pause and resume SwiftUI animations

Easily pause and resume SwiftUI animations

swiftui-pausable-animation Easily pause and resume SwiftUI animations! Installation This component is distributed as a Swift package. Just add this re

May 23, 2022

A library for building an internal/development support app easily

A library for building an internal/development support app easily

Scenarios A library supporting fast prototyping for iOS Projects. Introduction Challenges of mobile frontend development Stories with multiple require

Jun 5, 2022

SwiftUI Package for Configurable Confetti Animation πŸŽ‰

SwiftUI Package for Configurable Confetti Animation πŸŽ‰

🎊 ConfettiSwiftUI 🎊 Swift package for displaying configurable confetti animation. Find the demo project here. Installation: It requires iOS 14 and X

Jun 27, 2022

A simple animated progress bar in Swift

A simple animated progress bar in Swift

DSGradientProgressView Introduction DSGradientProgressView is a simple and customizable animated progress bar written in Swift. Inspired by GradientPr

May 16, 2022

A simple spritesheet animation system for Raylib on Swift.

A simple spritesheet animation system for Raylib on Swift.

About A simple spritesheet animation system for Raylib on Swift. Aeni allows you to quickly and easily animate your spritesheet in your Raylib for Swi

May 7, 2022

Advanced Natural Motion Animations, Simple Blocks Based Syntax

Advanced Natural Motion Animations, Simple Blocks Based Syntax

FlightAnimator Moved to Swift 3.1 Support: For Swift 3.1 - Use tag Version 0.9.9 See Installation Instructions for clarification Introduction FlightAn

Feb 8, 2022

Simple Interface Core Animation. Run type-safe animation sequencially or parallelly

Simple Interface Core Animation. Run type-safe animation sequencially or parallelly

Simple Interface Core Animation Sica can execute various animations sequentially or parallelly. Features Animation with duration and delay parallel /

Jun 19, 2022

Simple and powerful animated progress bar with dots

Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements iOS 8.0+ Swift 3.0+ Installatio

Apr 1, 2021

Simple Animated tabbar with native control

Simple Animated tabbar with native control

SSCustomTabbar Simple Animated tabbar with native control. Requirements iOS 11.0+ Xcode 10.0+ Installation SSCustomTabbar doesn't contain any external

Jun 17, 2022
Related tags
VCore is a Swift collection containing objects, functions, and extensions that I use for all my projects
VCore is a Swift collection containing objects, functions, and extensions that I use for all my projects

VCore Table of Contents Description Library Structure Architecture Gateway Demo Installation Versioning Contact Description VCore is a Swift collectio

May 26, 2022
A collection of animations for iOS. Simple, just add water animations.
A collection of animations for iOS. Simple, just add water animations.

DCAnimationKit A collection of animations for iOS Simply, just add water! DCAnimationKit is a category on UIView to make animations easy to perform. E

Jun 13, 2022
An easy way to add a simple, shimmering effect to any view in an iOS app.
An easy way to add a simple, shimmering effect to any view in an iOS app.

Shimmer Shimmer is an easy way to add a shimmering effect to any view in your app. It's useful as an unobtrusive loading indicator. Shimmer was origin

Jun 17, 2022
SAHistoryNavigationViewController realizes iOS task manager like UI in UINavigationContoller. Support 3D Touch!
SAHistoryNavigationViewController realizes iOS task manager like UI in UINavigationContoller. Support 3D Touch!

SAHistoryNavigationViewController realizes iOS task manager like UI in UINavigationContoller. Support 3D Touch!

Jun 18, 2022
Add smooth water waves to your views.
Add smooth water waves to your views.

WXWaveView Add pretty and smooth waves to your views! The wave can be added to any type of view. δΈ­ζ–‡θ―΄ζ˜Ž e.g. Integration Cocoapods: pod 'WXWaveView' Or

Apr 6, 2022
MotionBlur allows you to add motion blur effect to iOS animations.
MotionBlur allows you to add motion blur effect to iOS animations.

MotionBlur MotionBlur allows you to add motion blur effect to your animations (currently only position's change). See the accompanying blog post to le

Apr 22, 2022
An easy way to add a shimmering effect to any view with just one line of code. It is useful as an unobtrusive loading indicator.
An easy way to add a shimmering effect to any view with just one line of code. It is useful as an unobtrusive loading indicator.

LoadingShimmer An easy way to add a shimmering effect to any view with just single line of code. It is useful as an unobtrusive loading indicator. Thi

Jun 19, 2022
Jan 26, 2022
An app that will help UI/UX designers and iOS developpers to easily work together, using demos and examples about iOS capabilities, limitations, ecosystem, ...

Demoapp Work in progress... ?? What's about? It's an app built in SwiftUI that will help UI/UX designers and iOS developpers to work together smoothly

Dec 19, 2021
Easily build advanced custom animations on iOS.
Easily build advanced custom animations on iOS.

INTUAnimationEngine makes it easy to build advanced custom animations on iOS. INTUAnimationEngine provides a friendly interface to drive custom animat

Jun 22, 2022