Skip to content

Commit

Permalink
Cocoapods version update
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronnel Davis committed Jul 25, 2018
1 parent f5649a5 commit 811d41e
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 100 deletions.
2 changes: 1 addition & 1 deletion BubblePicker.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'BubblePicker'
s.version = '0.1.0'
s.version = '1.0.0'
s.summary = 'An easy-to-use picker view built on UIKitDynamics which can be used for content picking for iOS'

# This description is used to generate tags and improve search results.
Expand Down
62 changes: 40 additions & 22 deletions BubblePicker/Classes/BubblePicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,28 @@

import UIKit

var BPSelectedIndices = [Int]()

var BPAnimator: UIDynamicAnimator!
var BPCollision: UICollisionBehavior!
var BPGravity: UIFieldBehavior!
var BPDynamics: UIDynamicItemBehavior!


public protocol BubblePickerDelegate: AnyObject {

func numberOfItems(in bubblepicker: BubblePicker) -> Int;

func bubblePicker(_: BubblePicker, nodeFor indexPath: IndexPath) -> BubblePickerNode;
func bubblePicker(_: BubblePicker, didSelectNodeAt indexPath: IndexPath);
func bubblePicker(_: BubblePicker, didDeselectNodeAt indexPath: IndexPath);
}

}

public class BubblePicker: UIView {

public weak var delegate: BubblePickerDelegate?
public var selectedIndices = [Int]()

var nodes = [BubblePickerNode]()

var BPAnimator: UIDynamicAnimator!
var BPCollision: UICollisionBehavior!
var BPGravity: UIFieldBehavior!
var BPDynamics: UIDynamicItemBehavior!

var circles = [BubblePickerNode]()
var gravPos: CGPoint!

override public init(frame: CGRect) {
Expand All @@ -40,17 +39,34 @@ public class BubblePicker: UIView {
super.init(coder: aDecoder);
}

public func getSelected() -> [Int]{
return selectedIndices;
}

public func setSelected(_ arr: [Int]){
self.selectedIndices = arr;

for node in self.nodes{
if(selectedIndices.contains(node.index)){
node.setSelected(true);
}
else{
node.setSelected(false);
}
}
}

public func reloadData(){

guard let delegate = delegate else {
return
}

circles = [BubblePickerNode]()
nodes = [BubblePickerNode]()
let items = delegate.numberOfItems(in: self);

BPAnimator = UIDynamicAnimator(referenceView: self)
BPAnimator.setValue(true, forKey: "debugEnabled") // Private API. See the bridging header.
//BPAnimator.setValue(true, forKey: "debugEnabled") // Private API. See the bridging header.
self.isUserInteractionEnabled = true

BPGravity = UIFieldBehavior.radialGravityField(position: self.center)
Expand All @@ -60,18 +76,19 @@ public class BubblePicker: UIView {
gravPos = CGPoint(x: frame.midX, y: frame.midY)

for i in 0..<items{
let circle = delegate.bubblePicker(self, nodeFor: IndexPath(item: i, section: 0))
circle.index = i;
circles.append(circle);
self.addSubview(circle)
BPGravity.addItem(circle)
let node = delegate.bubblePicker(self, nodeFor: IndexPath(item: i, section: 0))
node.index = i;
node.bubblepicker = self;
nodes.append(node);
self.addSubview(node)
BPGravity.addItem(node)
}

BPDynamics = UIDynamicItemBehavior(items: circles);
BPDynamics = UIDynamicItemBehavior(items: nodes);
BPDynamics.allowsRotation = false;
BPDynamics.resistance = 0.8

BPCollision = UICollisionBehavior(items: circles)
BPCollision = UICollisionBehavior(items: nodes)
BPCollision.setTranslatesReferenceBoundsIntoBoundary(with: UIEdgeInsets(top: 0, left: -500, bottom: 0, right: -500))

BPAnimator.addBehavior(BPDynamics)
Expand All @@ -88,7 +105,9 @@ public class BubblePicker: UIView {
newX = max(0, newX);
newX = min(frame.width, newX);

let newY = gravPos.y;
var newY = gravPos.y + recogniser.translation(in: self).y;
newY = max(frame.height*0.25, newY);
newY = min(frame.height*0.75, newY);

switch recogniser.state {
case .ended:
Expand All @@ -99,8 +118,7 @@ public class BubblePicker: UIView {
BPGravity.position = CGPoint(x: newX, y: newY)
break;

default:
print("panning");
default: break;
}
}

Expand Down
52 changes: 38 additions & 14 deletions BubblePicker/Classes/BubblePickerNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ import UIKit

public class BubblePickerNode: UIView {

public var label: UILabel!
public var font: UIFont = UIFont(name: "Avenir-Heavy", size: 14)!
public var selectedFont: UIFont = UIFont(name: "Avenir", size: 22)!
public var textColor: UIColor = UIColor.white

var bubblepicker: BubblePicker!

var label: UILabel!
var imageView: UIImageView!

var index: Int!
var isExpanded = false;

Expand All @@ -26,6 +33,11 @@ public class BubblePickerNode: UIView {
let screenHeight = screenSize.height
super.init(frame: CGRect(x: screenWidth/2 + marginLeft - 100 + CGFloat(arc4random_uniform(100)), y: screenHeight/2 - 100 + CGFloat(arc4random_uniform(100)), width: 100, height: 100))

imageView = UIImageView(image: image);
imageView.frame = CGRect(x: 0, y: 0, width: 100, height: 100);
imageView.alpha = 0;
self.addSubview(imageView);

let maskPath = UIBezierPath(roundedRect: CGRect(x: 3, y: 3, width: frame.width - 6, height: frame.height - 6), cornerRadius: 47)
let maskLayer = CAShapeLayer()
maskLayer.frame = self.bounds
Expand All @@ -34,9 +46,9 @@ public class BubblePickerNode: UIView {

self.label = UILabel(frame: self.bounds)
self.label.text = title
self.label.textColor = UIColor.white
self.label.textColor = self.textColor
self.label.textAlignment = .center
self.label.font = UIFont(name: "Avenir-Heavy", size: 14)
self.label.font = self.font;
self.addSubview(self.label)

self.backgroundColor = color
Expand All @@ -60,16 +72,24 @@ public class BubblePickerNode: UIView {
}

@objc func tapped(recogniser: UITapGestureRecognizer){
if(isExpanded){
self.bubblepicker.delegate?.bubblePicker(self.bubblepicker, didDeselectNodeAt: IndexPath(item: self.index, section: 0))
self.bubblepicker.selectedIndices.remove(at: self.bubblepicker.selectedIndices.index(of: self.index)!)
}
else{
self.bubblepicker.delegate?.bubblePicker(self.bubblepicker, didSelectNodeAt: IndexPath(item: self.index, section: 0))
self.bubblepicker.selectedIndices.append(self.index);
}
setSelected(!isExpanded);
}

public func setSelected(_ flag: Bool){
func setSelected(_ flag: Bool){

isExpanded = flag;

BPAnimator.removeBehavior(BPDynamics)
BPAnimator.removeBehavior(BPGravity)
BPAnimator.removeBehavior(BPCollision)
self.bubblepicker.BPAnimator.removeBehavior(self.bubblepicker.BPDynamics)
self.bubblepicker.BPAnimator.removeBehavior(self.bubblepicker.BPGravity)
self.bubblepicker.BPAnimator.removeBehavior(self.bubblepicker.BPCollision)

var maskPath: UIBezierPath!

Expand All @@ -78,27 +98,31 @@ public class BubblePickerNode: UIView {

maskPath = UIBezierPath(roundedRect: CGRect(x: 3, y: 3, width: bounds.width - 6, height: bounds.height - 6), cornerRadius: 47)

imageView.frame = CGRect(x: 0, y: 0, width: 160, height: 160);
imageView.alpha = 0;

self.label.frame = self.bounds
self.label.font = UIFont(name: "Avenir-Heavy", size: 14)
BPSelectedIndices.remove(at: BPSelectedIndices.index(of: self.index)!)
self.label.font = self.font
}
else{
self.bounds = CGRect(origin: CGPoint.zero, size: CGSize(width: 160, height: 160))

imageView.frame = CGRect(x: 0, y: 0, width: 160, height: 160);
imageView.alpha = 0.5;

maskPath = UIBezierPath(roundedRect: CGRect(x: 3, y: 3, width: bounds.width - 6, height: bounds.height - 6), cornerRadius: 77)

self.label.frame = self.bounds
self.label.font = UIFont(name: "Avenir", size: 22)
BPSelectedIndices.append(self.index);
self.label.font = self.selectedFont;
}

let maskLayer = CAShapeLayer()
maskLayer.frame = self.bounds
maskLayer.path = maskPath.cgPath
self.layer.mask = maskLayer

BPAnimator.addBehavior(BPDynamics)
BPAnimator.addBehavior(BPGravity)
BPAnimator.addBehavior(BPCollision)
self.bubblepicker.BPAnimator.addBehavior(self.bubblepicker.BPDynamics)
self.bubblepicker.BPAnimator.addBehavior(self.bubblepicker.BPGravity)
self.bubblepicker.BPAnimator.addBehavior(self.bubblepicker.BPCollision)
}
}
55 changes: 0 additions & 55 deletions BubblePicker/Classes/Extensions.swift

This file was deleted.

4 changes: 4 additions & 0 deletions Example/BubblePicker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
34DCD13B2108EFFE00468794 /* dubai.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 34DCD13A2108EFFE00468794 /* dubai.jpg */; };
3EB3EBA862E6C0A96B2C49D8 /* Pods_BubblePicker_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03232410FDAF94F2DAFC5060 /* Pods_BubblePicker_Example.framework */; };
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; };
Expand All @@ -31,6 +32,7 @@
03232410FDAF94F2DAFC5060 /* Pods_BubblePicker_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_BubblePicker_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
08F8DF95CE39F32BA891B54B /* Pods_BubblePicker_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_BubblePicker_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
0A6F100D57A8BF4C604F5D41 /* Pods-BubblePicker_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BubblePicker_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-BubblePicker_Example/Pods-BubblePicker_Example.debug.xcconfig"; sourceTree = "<group>"; };
34DCD13A2108EFFE00468794 /* dubai.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = dubai.jpg; sourceTree = "<group>"; };
3EB72F3194E4DDC9363263E6 /* Pods-BubblePicker_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BubblePicker_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-BubblePicker_Example/Pods-BubblePicker_Example.release.xcconfig"; sourceTree = "<group>"; };
607FACD01AFB9204008FA782 /* BubblePicker_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BubblePicker_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -93,6 +95,7 @@
607FACD21AFB9204008FA782 /* Example for BubblePicker */ = {
isa = PBXGroup;
children = (
34DCD13A2108EFFE00468794 /* dubai.jpg */,
607FACD51AFB9204008FA782 /* AppDelegate.swift */,
607FACD71AFB9204008FA782 /* ViewController.swift */,
607FACD91AFB9204008FA782 /* Main.storyboard */,
Expand Down Expand Up @@ -252,6 +255,7 @@
files = (
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */,
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */,
34DCD13B2108EFFE00468794 /* dubai.jpg in Resources */,
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
10 changes: 6 additions & 4 deletions Example/BubblePicker/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

bubblePicker.delegate = self;
bubblePicker.reloadData();
bubblePicker.setSelected([0, 2, 3, 4]);

}

override func didReceiveMemoryWarning() {
Expand All @@ -36,16 +38,16 @@ extension ViewController: BubblePickerDelegate {
}

func bubblePicker(_: BubblePicker, nodeFor indexPath: IndexPath) -> BubblePickerNode {
let node = BubblePickerNode(title: items[indexPath.item], color: UIColor.red, image: UIImage());
let node = BubblePickerNode(title: items[indexPath.item], color: UIColor.red, image: UIImage(named: "dubai.jpg")!);
return node;
}

func bubblePicker(_: BubblePicker, didSelectNodeAt indexPath: IndexPath) {

print("Did select");
}

func bubblePicker(_: BubblePicker, didDeselectNodeAt indexPath: IndexPath) {

print("Did deselect");
}

}
Binary file added Example/BubblePicker/dubai.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 811d41e

Please sign in to comment.