Play BreakOut while loading - A playable pull to refresh view using SpriteKit

Overview

BreakOutToRefresh

Play BreakOut while loading - A playable pull to refresh view using SpriteKit

BreakOutToRefresh uses SpriteKit to add a playable mini game to the pull to refresh view in a table view. In this case the mini game is BreakOut but a lot of other mini games could be presented in this space.

Book

If you like this repository and like'd to give me something back, I wrote a book about funny location based projects for iOS. Please check it out: Build Location-Based Projects for iOS

Installation

CocoaPods

Add this to your Podfile:

use_frameworks!

pod 'BreakOutToRefresh'

Manual

Add BreakOutToRefreshView.swift to your project.

Usage

If you need it only once in your app, add this to your table view controller:

class DemoTableViewController: UITableViewController {

  var refreshView: BreakOutToRefreshView!
  
  // ...
  
  override func viewDidLoad() {
    super.viewDidLoad()
    
    refreshView = BreakOutToRefreshView(scrollView: tableView)
    refreshView.refreshDelegate = self
  
    // configure the refresh view
    refreshView.scenebackgroundColor = .white
    refreshView.textColor = .black
    refreshView.paddleColor = .brown
    refreshView.ballColor = .darkGray
    refreshView.blockColors = [.blue, .green, .red]
  
    tableView.addSubview(refreshView)
  }  
}

extension DemoTableViewController: UIScrollViewDelegate {
 
  override func scrollViewDidScroll(scrollView: UIScrollView) {
    refreshView.scrollViewDidScroll(scrollView)
  }
  
  override func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
    refreshView.scrollViewWillEndDragging(scrollView, withVelocity: velocity, targetContentOffset: targetContentOffset)
  }
  
  override func scrollViewWillBeginDragging(scrollView: UIScrollView) {
    refreshView.scrollViewWillBeginDragging(scrollView)
  }
}

extension DemoTableViewController: BreakOutToRefreshDelegate {
  
  func refreshViewDidRefresh(refreshView: BreakOutToRefreshView) {
    // load stuff from the internet
  }

}

In case you need it more than once in your app, add the setup to viewWillAppear and clean up in viewWillDisappear like this:

override func viewWillAppear(_ animated: Bool) {
  super.viewWillAppear(animated)
  
  refreshView = BreakOutToRefreshView(scrollView: tableView)
  refreshView.refreshDelegate = self
  
  // configure the refresh view
  refreshView.scenebackgroundColor = .white
  refreshView.textColor = .black
  refreshView.paddleColor = .brown
  refreshView.ballColor = .darkGray
  refreshView.blockColors = [.blue, .green, .red]
  
  tableView.addSubview(refreshView)
}

override func viewWillDisappear(_ animated: Bool) {
  super.viewWillDisappear(animated)
  
  refreshView.removeFromSuperview()
  refreshView = nil
}

When the loading of new content is finished, call endRefreshing() of the refreshView.

When endRefreshing() is called the mini game doesn't stop immediately. The game stops (and the view is dismissed) when the user lifts the finger. If you like to end the mini game immediately set the forceEnd property to true.

Status

It's kind of beta status.

Feedback

If you use this code or got inspired by the idea and build an app with an even more awesome PullToRefresh game, please let me know.

Author

Dominik Hauser

Twitter: @dasdom

dasdom.github.io

Support

If you want to give me something back, I would highly appreciate if you buy my book about Test-Driven Development with Swift and give me feedback about it.

Thanks

Thanks to Ben Oztalay and raywenderlich.com for inspiration.

Licence

MIT

You might also like...
Confetti View lets you create a magnificent confetti view in your app
Confetti View lets you create a magnificent confetti view in your app

ConfettiView Confetti View lets you create a magnificent confetti view in your app. This was inspired by House Party app's login screen. Written in Sw

Full configurable spreadsheet view user interfaces for iOS applications. With this framework, you can easily create complex layouts like schedule, gantt chart or timetable as if you are using Excel.
Full configurable spreadsheet view user interfaces for iOS applications. With this framework, you can easily create complex layouts like schedule, gantt chart or timetable as if you are using Excel.

kishikawakatsumi/SpreadsheetView has moved! It is being actively maintained at bannzai/SpreadsheetView. This fork was created when the project was mov

A paging scroll view for SwiftUI, using internal SwiftUI components
A paging scroll view for SwiftUI, using internal SwiftUI components

PagingView A paging scroll view for SwiftUI, using internal SwiftUI components. This is basically the same as TabView in the paging mode with the inde

A custom stretchable header view for UIScrollView or any its subclasses with UIActivityIndicatorView and iPhone X safe area support for content reloading. Built for iOS 10 and later.

Arale A custom stretchable header view for UIScrollView or any its subclasses with UIActivityIndicatorView support for reloading your content. Built f

A simple, customizable view for efficiently collecting country information in iOS apps.
A simple, customizable view for efficiently collecting country information in iOS apps.

CountryPickerView CountryPickerView is a simple, customizable view for selecting countries in iOS apps. You can clone/download the repository and run

Elissa displays a notification on top of a UITabBarItem or any UIView anchor view to reveal additional information.
Elissa displays a notification on top of a UITabBarItem or any UIView anchor view to reveal additional information.

Elissa Attach a local notification to any UIView to reveal additional user guidance. Usage Example Per default, Elissa will try to align to the center

Cool Animated music indicator view written in Swift
Cool Animated music indicator view written in Swift

Cool Animated music indicator view written in Swift. ESTMusicIndicator is an implementation of NAKPlaybackIndicatorView in Swift for iOS 8. 本人著作的书籍《La

A child view controller framework that makes setting up your parent controllers as easy as pie.
A child view controller framework that makes setting up your parent controllers as easy as pie.

Description Family is a child view controller framework that makes setting up your parent controllers as easy as pie. With a simple yet powerful publi

An easy to use FAQ view for iOS written in Swift
An easy to use FAQ view for iOS written in Swift

FAQView An easy to use FAQ view for iOS written in Swift. This view is a subclass of UIView. Setup with CocoaPods If you are using CocoaPods add this

Comments
  • Add dynamic framework and game restarts when ball hits right edge

    Add dynamic framework and game restarts when ball hits right edge

    Should've done this as two separate pull requests, my apologies.

    The dynamic framework enables Carthage support, it would be nice to do a version'd release (push a tag titled something like v0.1.0 or whatever version you feel is right).

    The game will now immediately restart when the ball hits the right edge of the view.

    Thanks!

    opened by younata 1
  • Fix bug where app would crash before playing the game

    Fix bug where app would crash before playing the game

    If the user tries to scroll down before playing the game for the first time, updateLabel would try and unwrap an Optional and fail, because it can't find the appropriate SKSpriteNode.

    opened by franklinsch 1
  • Logo proposal

    Logo proposal

    Greetings, @dasdom

    I am a designer in development and an open source enthusiast who would love to contribute to your project by designing a logo for it. I found your project exploring GitHub and found it interesting. About the process, we would be working together to create a logo that fits best with your project. The process is, of course, totally free and you can quit whenever you want. In case you agree, it would be useful if you had any ideas (shapes, colors, etc) to have something to start with.

    Best regards!

    opened by michaelizergit 0
Owner
Dominik Hauser
iOS, Swift, ObjC, Author
Dominik Hauser
SpriteKit Floating Bubble Picker (inspired by Apple Music) 🧲

Magnetic Magnetic is a customizable bubble picker like the Apple Music genre selection. Demo Video $ pod try Magnetic Features Adding/Removing Nodes

Lasha Efremidze 1.4k Jan 6, 2023
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

Jogendra 1.4k Jan 4, 2023
Windless makes it easy to implement invisible layout loading view.

Windless Windless makes it easy to implement invisible layout loading view. Contents Requirements Installation Usage Looks Credits Communication Licen

ArLupin 940 Dec 22, 2022
Pull up controller with multiple sticky points like in iOS Maps

PullUpController Create your own pull up controller with multiple sticky points like in iOS Maps Features Multiple sticky points Landscape support Scr

Mario Iannotta 1.2k Dec 22, 2022
📹 Framework to Play a Video in the Background of any UIView

SwiftVideoBackground is an easy to use Swift framework that provides the ability to play a video on any UIView. This provides a beautiful UI for login

Wilson Ding 334 Jan 7, 2023
A number of preset loading indicators created with SwiftUI

ActivityIndicatorView A number of preset loading indicators created with SwiftUI We are a development agency building phenomenal apps. Usage Create an

Exyte 956 Dec 26, 2022
Beautiful animated placeholders for showing loading of data

KALoader Create breautiful animated placeholders for showing loading of data. You can change colors like you want. Swift 4 compatible. Usage To add an

Kirill Avery 105 May 2, 2022
A collection of awesome loading animations

NVActivityIndicatorView ⚠️ Check out LoaderUI (ready to use with Swift Package Mananger supported) for SwiftUI implementation of this. ?? Introduction

Vinh Nguyen 10.3k Dec 27, 2022
Placeholder views based on content, loading, error or empty states

StatefulViewController A protocol to enable UIViewControllers or UIViews to present placeholder views based on content, loading, error or empty states

Alexander Schuch 2.1k Dec 8, 2022
A way to quickly add a notification badge icon to any view. Make any view of a full-fledged animated notification center.

BadgeHub A way to quickly add a notification badge icon to any view. Demo/Example For demo: $ pod try BadgeHub To run the example project, clone the r

Jogendra 772 Dec 28, 2022