{"id":7990,"date":"2015-11-16T01:01:27","date_gmt":"2015-11-16T01:01:27","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/16\/dasdom-breakouttorefresh\/"},"modified":"2022-08-30T15:03:04","modified_gmt":"2022-08-30T15:03:04","slug":"dasdom-breakouttorefresh","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/16\/dasdom-breakouttorefresh\/","title":{"rendered":"dasdom\/BreakOutToRefresh"},"content":{"rendered":"<p>Play BreakOut while loading &#8211; A playable pull to refresh view using SpriteKit<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/raw.githubusercontent.com\/dasdom\/BreakOutToRefresh\/master\/PullToRefreshDemo\/what.gif\" \/><\/p>\n<p>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.<\/p>\n<h2>Swift 1.2<\/h2>\n<p>The code is updated for Swift 1.2. If you like to use it with Xcode 6.1.1 and Swift 1.1 checkout the tag Swift1_1.<\/p>\n<h2>Installation<\/h2>\n<p>Add <strong>BreakOutToRefreshView.swift<\/strong> to your project.<\/p>\n<h2>Usage<\/h2>\n<p>Add this to your table view controller:<\/p>\n<pre><code>var refreshView: BreakOutToRefreshView!\n  \n  override func viewDidLoad() {\n    super.viewDidLoad()\n    \n    let refreshHeight = CGFloat(100)\n    refreshView = BreakOutToRefreshView(scrollView: tableView)\n    refreshView.delegate = self\n    \n    \/\/ configure the colors of the refresh view\n    refreshView.scenebackgroundColor = UIColor(hue: 0.68, saturation: 0.9, brightness: 0.3, alpha: 1.0)\n    refreshView.paddleColor = UIColor.lightGrayColor()\n    refreshView.ballColor = UIColor.whiteColor()\n    refreshView.blockColors = [UIColor(hue: 0.17, saturation: 0.9, brightness: 1.0, alpha: 1.0), UIColor(hue: 0.17, saturation: 0.7, brightness: 1.0, alpha: 1.0), UIColor(hue: 0.17, saturation: 0.5, brightness: 1.0, alpha: 1.0)]\n    \n    tableView.addSubview(refreshView)\n    \n  }\n  \nextension DemoTableViewController: UIScrollViewDelegate {\n \n  override func scrollViewDidScroll(scrollView: UIScrollView) {\n    refreshView.scrollViewDidScroll(scrollView)\n  }\n  \n  override func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer) {\n    refreshView.scrollViewWillEndDragging(scrollView, withVelocity: velocity, targetContentOffset: targetContentOffset)\n  }\n  \n  override func scrollViewWillBeginDragging(scrollView: UIScrollView) {\n    refreshView.scrollViewWillBeginDragging(scrollView)\n  }\n}\n\nextension DemoTableViewController: BreakOutToRefreshDelegate {\n  \n  func refreshViewDidRefresh(refreshView: BreakOutToRefreshView) {\n    \/\/ load stuff from the internet\n  }\n\n}\n<\/code><\/pre>\n<p>When the loading of new content is finished, call <code>endRefreshing()<\/code> of the <code>refreshView<\/code>.<\/p>\n<p>When <code>endRefreshing()<\/code> is called the mini game doesn\u2019t 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 <code>forceEnd<\/code> property to true.<\/p>\n<h2>Status<\/h2>\n<p>It\u2019s kind of beta status.<\/p>\n<h2>To do<\/h2>\n<ul>\n<li>Add scoring<\/li>\n<li>Add ending of the game when the ball hits the right wall<\/li>\n<li>Add levels<\/li>\n<\/ul>\n<h2>Feedback<\/h2>\n<p>If you use this code or got inspired by the idea and build an app with a even more awesome PullToRefresh game, please let me know.<\/p>\n<h2>Author<\/h2>\n<p>Dominik Hauser<\/p>\n<p>App.net: @dasdom<\/p>\n<p>Twitter: @dasdom<\/p>\n<p>swiftandpainless.com<\/p>\n<h2>Thanks<\/h2>\n<p>Thanks to Ben Oztalay and raywenderlich.com for inspiration.<\/p>\n<h2>Licence<\/h2>\n<p>MIT<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Play BreakOut while loading &#8211; 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. Swift 1.2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7990","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7990","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7990"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7990\/revisions"}],"predecessor-version":[{"id":8718,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7990\/revisions\/8718"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}