Magnetic
  • August 12, 2023

Magnetic is a customizable bubble picker like the Apple Music genre selection.

$ pod try Magnetic

Features


  •  Adding/Removing Nodes
  •  Selection/Deselection/Removed Animations
  •  Multiple Selection
  •  Images
  •  Multiline Label
  •  Documentation

Requirements


  • iOS 13.0+ (Magnetic 3.3.x), iOS 9.0+ (Magnetic 3.2.1)
  • Swift 5 (Magnetic 3.x), Swift 4 (Magnetic 2.x), Swift 3 (Magnetic 1.x)

Usage


Magnetic object is an SKScene.

To display, you present it from an SKView object.

import Magnetic

class ViewController: UIViewController {

var magnetic: Magnetic?

override func loadView() {
super.loadView()

let magneticView = MagneticView(frame: self.view.bounds)
magnetic = magneticView.magnetic
self.view.addSubview(magneticView)
}

}

Properties

var magneticDelegate: MagneticDelegate? // magnetic delegate
var allowsMultipleSelection: Bool // controls whether you can select multiple nodes. defaults to true
var selectedChildren: [Node] // returns selected chidren

Nodes

Node object is a SKShapeNode subclass.

Interaction

// add circular node
let node = Node(text: “Italy”, image: UIImage(named: “italy”), color: .red, radius: 30)
magnetic.addChild(node)

// add custom node
let node = Node(text: “France”, image: UIImage(named: “france”), color: .blue, path: path, marginScale: 1.1)
magnetic.addChild(node)

// remove node
node.removeFromParent()

Properties

var text: String? // node text
var image: UIImage? // node image
var color: UIColor // node color

Animations

override func selectedAnimation() {
// override selected animation
}

override func deselectedAnimation() {
// override deselected animation
}

override func removedAnimation(completion: @escaping () -> Void) {
// override removed animation
}

Delegation

The MagneticDelegate protocol provides a number of functions for observing the current state of nodes.

func magnetic(_ magnetic: Magnetic, didSelect node: Node) {
// handle node selection
}

func magnetic(_ magnetic: Magnetic, didDeselect node: Node) {
// handle node deselection
}

Customization

Subclass the Node for customization.

For example, a node with an image by default:

class ImageNode: Node {
override var image: UIImage? {
didSet {
texture = image.map { SKTexture(image: $0) }
}
}
override func selectedAnimation() {}
override func deselectedAnimation() {}
}

Installation


CocoaPods

To install with CocoaPods, simply add this in your Podfile:

use_frameworks!
pod “Magnetic”

Carthage

To install with Carthage, simply add this in your Cartfile:

github “efremidze/Magnetic”

GitHub


View Github

#animation #apple #applemusic #bubble #carthage #cocoapods #floating #ios #music #picker #spritekit #swift
YOU MIGHT ALSO LIKE...
exyte

     

camerakit-ios

CameraKit helps you add reliable camera to your app quickly. Our open source camera platform provides consistent capture results, service ...

HybridCamera

[video width="192" height="416" mp4="https://swiftgit.com/wp-content/uploads/2024/12/68747470733a2f2f7261776769742e636f6d2f7374796c656b69742f696d672f6d61737465722f7669645f6564697465645f325f326d622e676966.mp4"][/video]

TakeASelfie

An iOS framework that uses the front camera, detects your face and takes a selfie. This api opens the front ...

iOS-Depth-Sampler

Code examples of Depth APIs in iOS