Git Product home page Git Product logo

blbubblefilters's Introduction

BLBubbleFilters Version License

Platforms CocoaPods Compatible Carthage compatible Twitter

BLBubbleFilters

BLBubbleFilters

BLBubbleFilters gives you bubble filters à la Apple Music.

Inspired by: SIFloatingCollection_Swift

Specs

  • SpriteKit
  • iOS 9+
  • tvOS 9+

Usage

The starting point of using BLBubbleFilters is the BLBubbleScene class. We begin by initialising one:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    BLBubbleScene *scene = [BLBubbleScene sceneWithSize:CGSizeMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0)];
    scene.backgroundColor = [UIColor whiteColor];
    scene.bubbleDataSource = <#code#>;
    scene.bubbleDelegate = <#code#>;

    [(SKView *)self.view presentScene:scene];
}

Notes:

  1. We highly recommend initialising a BLBubbleScene on viewWillAppear: so it gets correctly adjusted to the screen size.
  2. The example above assumes your view controller's view is a SKView.

Scene data source

You must provide the BLBubbleScene with a data source conforming to the BLBubbleSceneDataSource protocol. Its two required methods are:

//provides the scene with the number of bubbles to present
- (NSInteger)numberOfBubblesInBubbleScene:(BLBubbleScene *)scene {
    return <#code#>;
}

And:

- (id<BLBubbleModel>)bubbleScene:(BLBubbleScene *)scene
           modelForBubbleAtIndex:(NSInteger)index
{
    return <#code#>;
}

The BLBubbleModel protocol provides a bubble with some of the visual information it needs to draw itself.

Scene delegate

You may set the scene's delegate, if you'd like to be notified when a bubble is selected:

- (void)bubbleScene:(BLBubbleScene *)scene
    didSelectBubble:(BLBubbleNode *)bubble
            atIndex:(NSInteger)index
{
    //a bubble has been tapped
}

Example

A typical implementation of BLBubbleFilters looks like this:

#import "ViewController.h"
#import <BLBubbleFilters/BLBubbleFilters.h>
#import "Bubble.h"


@interface ViewController () <BLBubbleSceneDataSource, BLBubbleSceneDelegate>

@property (nonatomic, strong) NSArray<Bubble *> *bubbles;

@end


@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self setBubbles:@[[[Bubble alloc] initWithIndex:0],
                       [[Bubble alloc] initWithIndex:1],
                       [[Bubble alloc] initWithIndex:2],
                       [[Bubble alloc] initWithIndex:3]]];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    BLBubbleScene *scene = [BLBubbleScene sceneWithSize:self.view.bounds.size];
    scene.backgroundColor = [UIColor whiteColor];
    scene.bubbleDataSource = self;
    scene.bubbleDelegate = self;

    [(SKView *)self.view presentScene:scene];
}

#pragma mark Bubble Delegate

- (void)bubbleScene:(BLBubbleScene *)scene
    didSelectBubble:(BLBubbleNode *)bubble
            atIndex:(NSInteger)index
{
    NSLog(@"Bubble Pressed! %@", bubble);
    NSLog(@"The bubble is now on state %ld", (long)[bubble.model bubbleState]);
}

#pragma mark Bubble Data Source

- (NSInteger)numberOfBubblesInBubbleScene:(BLBubbleScene *)scene
{
    return self.bubbles.count;
}

- (id<BLBubbleModel>)bubbleScene:(BLBubbleScene *)scene
           modelForBubbleAtIndex:(NSInteger)index
{
    return [self.bubbles objectAtIndex:index];
}

@end

Note: Implementation of the Bubble Data Model is up to you. ;)

Requirements

  • iOS 8+
  • Obj-C
  • SpriteKit

Installation

Cocoapods

pod 'BLBubbleFilters', '~> 1.0'

Then #import <BLBubbleFilters/BLBubbleFilters.h> where needed.

Carthage

github "BellAppLab/BLBubbleFilters" ~> 1.0

Then #import <BLBubbleFilters/BLBubbleFilters.h> where needed.

Git Submodules

cd toYourProjectsFolder
git submodule add -b submodule --name BLBubbleFilters https://github.com/BellAppLab/BLBubbleFilters.git

Then drag the BLBubbleFilters folder into your Xcode project.

Author

Bell App Lab, [email protected]

Credits

Logo image by Jaohuarye from The Noun Project

License

BLBubbleFilters is available under the MIT license. See the LICENSE file for more info.

blbubblefilters's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

carabina subbu29

blbubblefilters's Issues

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.