{"id":3005,"date":"2021-11-26T09:30:00","date_gmt":"2021-11-26T08:30:00","guid":{"rendered":"http:\/\/www.albertopasca.it\/whiletrue\/?p=3005"},"modified":"2021-11-27T16:40:44","modified_gmt":"2021-11-27T15:40:44","slug":"swift-circular-button-bubbles-with-gravity","status":"publish","type":"post","link":"https:\/\/www.albertopasca.it\/whiletrue\/swift-circular-button-bubbles-with-gravity\/","title":{"rendered":"Swift &#8211; Circular button bubbles with gravity"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>T<\/strong>oday I want to show how to use the <a href=\"https:\/\/github.com\/elpsk\/Gravity\" target=\"_blank\" rel=\"noreferrer noopener\">GravitySDK<\/a> &#x1f680; (as discussed in the <a href=\"http:\/\/www.albertopasca.it\/whiletrue\/swift-have-fun-with-gravitybehavior-and-dynamicanimator\/\" target=\"_blank\" rel=\"noreferrer noopener\">previous post<\/a>) to make an <strong>animated bubbles buttons<\/strong> that falling around with gravity, like this:<\/p>\n\n\n\n<figure class=\"wp-block-gallery columns-3 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"231\" height=\"500\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.30.png?resize=231%2C500\" alt=\"\" data-id=\"3009\" data-full-url=\"http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.30.png\" data-link=\"http:\/\/www.albertopasca.it\/whiletrue\/?attachment_id=3009\" class=\"wp-image-3009\" srcset=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.30.png?w=231&amp;ssl=1 231w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.30.png?resize=139%2C300&amp;ssl=1 139w\" sizes=\"auto, (max-width: 231px) 100vw, 231px\" \/><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"231\" height=\"500\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.49.png?resize=231%2C500\" alt=\"\" data-id=\"3006\" data-full-url=\"http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.49.png\" data-link=\"http:\/\/www.albertopasca.it\/whiletrue\/?attachment_id=3006\" class=\"wp-image-3006\" srcset=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.49.png?w=231&amp;ssl=1 231w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.49.png?resize=139%2C300&amp;ssl=1 139w\" sizes=\"auto, (max-width: 231px) 100vw, 231px\" \/><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"231\" height=\"500\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.43.png?resize=231%2C500\" alt=\"\" data-id=\"3007\" data-full-url=\"http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.43.png\" data-link=\"http:\/\/www.albertopasca.it\/whiletrue\/?attachment_id=3007\" class=\"wp-image-3007\" srcset=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.43.png?w=231&amp;ssl=1 231w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.43.png?resize=139%2C300&amp;ssl=1 139w\" sizes=\"auto, (max-width: 231px) 100vw, 231px\" \/><\/figure><\/li><\/ul><\/figure>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Let&#8217;s start!<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>F<\/strong>irst of all, add as Swift Package the &#8220;<strong>Gravity<\/strong>&#8221; SDK &#x1f60e;, importing the package:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/elpsk\/Gravity\">https:\/\/github.com\/elpsk\/Gravity<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And imports in your project the newest SDK:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift line-numbers\">import GravitySPM<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-background has-vivid-green-cyan-background-color has-vivid-green-cyan-color\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">BubbleView<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>C<\/strong>reate a new <strong>BubbleView<\/strong> class that extends from <strong>UIView<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In order to match exactly the circle view borders you should use a <strong>CAShapeLayer<\/strong> instead of a rounded view.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The difference is that using <strong>UIView<\/strong> with corner radius you have the view borders that collide with other views:<\/p>\n\n\n\n<figure class=\"wp-block-gallery columns-2 is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"314\" height=\"379\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/borders-1.png?resize=314%2C379\" alt=\"\" data-id=\"3024\" data-full-url=\"http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/borders-1.png\" data-link=\"http:\/\/www.albertopasca.it\/whiletrue\/?attachment_id=3024\" class=\"wp-image-3024\" srcset=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/borders-1.png?w=314&amp;ssl=1 314w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/borders-1.png?resize=249%2C300&amp;ssl=1 249w\" sizes=\"auto, (max-width: 314px) 100vw, 314px\" \/><figcaption class=\"blocks-gallery-item__caption\">UIView with corderRadius<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"440\" height=\"383\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/no-borders.png?resize=440%2C383\" alt=\"\" data-id=\"3025\" data-full-url=\"http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/no-borders.png\" data-link=\"http:\/\/www.albertopasca.it\/whiletrue\/?attachment_id=3025\" class=\"wp-image-3025\" srcset=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/no-borders.png?w=440&amp;ssl=1 440w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/no-borders.png?resize=300%2C261&amp;ssl=1 300w\" sizes=\"auto, (max-width: 440px) 100vw, 440px\" \/><figcaption class=\"blocks-gallery-item__caption\">UIView with CAShapeLayer<\/figcaption><\/figure><\/li><\/ul><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>C<\/strong>ode!<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift line-numbers\">class BubbleView: UIView {\n\n    var shapeLayer: CAShapeLayer = {\n        let _shapeLayer = CAShapeLayer()\n        _shapeLayer.fillColor = UIColor.clear.cgColor\n        _shapeLayer.allowsEdgeAntialiasing = true\n        _shapeLayer.backgroundColor = UIColor.clear.cgColor\n        return _shapeLayer\n    }()\n\n    override func layoutSubviews() {\n        super.layoutSubviews()\n\n        self.layer.cornerRadius = self.bounds.width \/ 2\n        self.backgroundColor = .white\n\n        layer.addSublayer(shapeLayer)\n        let center = CGPoint(x: bounds.midX, y: bounds.midY)\n        shapeLayer.path = circularPath(lineWidth: 0, center: center).cgPath\n    }\n\n    private func circularPath(lineWidth: CGFloat = 0, center: CGPoint = .zero) -&gt; UIBezierPath {\n        let radius = (min(bounds.width, bounds.height) - lineWidth) \/ 2\n        return UIBezierPath(arcCenter: center, radius: radius, startAngle: 0, endAngle: .pi * 2, clockwise: true)\n    }\n\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>T<\/strong>his class create a <strong>UIView<\/strong> with a circular <strong>CAShapeLayer<\/strong>. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is not enough because the collision type of this class must be setted to &#8220;<em>path<\/em>&#8220;, overriding the <strong>collisionBoundsType<\/strong> &#x1f6a7; and the <strong>collisionBoundingPath<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift line-numbers\">override var collisionBoundsType: UIDynamicItemCollisionBoundsType {\n    return .path\n}\n\noverride var collisionBoundingPath: UIBezierPath {\n    return circularPath()\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this way the collision respect exactly the circle  borders!<\/p>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-background has-vivid-red-background-color has-vivid-red-color\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>C<\/strong>reate the Bubbles &#x1f3be;&#x1f3c0;!<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now go into your ViewController and prepare the UI:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift line-numbers\">import GravitySPM\n\nclass ViewController: UIViewController {\n\n    var circles: [BubbleView] = []\n    var gravity: Gravity?\n    var gravityItems: [UIDynamicItem] = []\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        \/\/ create random BubbleView in random position\n        for idx in 0..&lt;6 {\n            let randX = Int.random(in: 100..&lt;Int(self.view.frame.size.width - 100))\n            let randY = Int.random(in: 100..&lt;Int(self.view.frame.size.height - 100))\n\n            let bubble = BubbleView(\n                frame: CGRect(x: randX, y: randY, width: 145, height: 145),\n                parentBound: self.view.bounds,\n                size: 145,\n                expansionDelta: 30,\n                padding: 30\n            )\n\n            bubble.delegate = self\n            bubble.tag = idx.offset\n            self.view.addSubview(bubble)\n        }\n\n        \/\/ prepare the bubbles to pass to SDK\n        gravityItems = self.view.subviews.filter{ $0 is BubbleView }\n\n        gravity = Gravity(\n            gravityItems: gravityItems, \/\/ &lt;&lt;-- your bubbles\n            collisionItems: nil,\n            referenceView: self.view,\n            boundary: UIBezierPath(rect: self.view.frame),\n            queue: nil)\n\n        \/\/ start gravity\n        gravity?.enable()\n    }\n\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;re done!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Build and run and you should see the bubbles falling around your main view!<\/p>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-background has-vivid-red-background-color has-vivid-red-color\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">&#x1f4cc; <strong>N<\/strong>OTE<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Remember to lock the orientation of your app&#8230;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift line-numbers\">override var supportedInterfaceOrientations: UIInterfaceOrientationMask {\n    return .portrait\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-background has-vivid-red-background-color has-vivid-red-color\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>E<\/strong>XTRA<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to make the bubbles touchable and scaled when touched, add into the <em>BubbleView<\/em> class the <strong>touched<\/strong> protocol:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift line-numbers\">protocol BubbleViewDelegate {\n    func didViewTouched( view: BubbleView )\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">and implement the <strong>touchesEnded<\/strong> delegate:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift line-numbers\">var delegate: BubbleViewDelegate?\n[...]\n\noverride func touchesEnded(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {\n    selected.toggle()\n        \n    shapeLayer.fillColor = selected ? UIColor.red.cgColor : UIColor.white.cgColor\n    self.backgroundColor = selected ? UIColor.clear : UIColor.white\n\n    if selected {\n        self.bounds.size.width = defaultSize! + expansionSize!\n        self.bounds.size.height = self.bounds.size.width\n    } else {\n        self.bounds.size.width = defaultSize!\n        self.bounds.size.height = self.bounds.size.width\n    }\n\n    self.delegate?.didViewTouched(view: self)\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>N<\/strong>ext, in your ViewController implement the protocol:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift line-numbers\">extension ViewController: BubbleViewDelegate {\n\n    func didViewTouched(view: BubbleView) {\n        let viewIndex = gravityItems.firstIndex { item in\n            if let vitem = item as? BubbleView {\n                return vitem.tag == view.tag\n            }\n            return false\n        }\n\n        if viewIndex != NSNotFound {\n            self.gravityItems.remove(at: viewIndex!)\n            self.gravityItems.append(view)\n        }\n\n        \/\/ remember to restart the gravity animator\n        \/\/ in order to re-layout all views with borders.\n        \/\/ Of course, only if the size change else is useless...\n        gravity?.restart()\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>F<\/strong>inal result &#x1f3a5;:<\/h2>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"1920\" style=\"aspect-ratio: 886 \/ 1920;\" width=\"886\" autoplay loop muted preload=\"auto\" src=\"http:\/\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/RPReplay_Final1637658774.mp4\"><\/video><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enjoy and share the bubbles! &#x1f389;&#x1f389;&#x1f389;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I want to show how to use the GravitySDK &#x1f680; (as discussed in the previous post) to make an animated bubbles buttons that falling around with gravity, like this:<\/p>\n","protected":false},"author":1,"featured_media":3036,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[115,1018,246,22,1019,1020,46,19,1021,18,252],"class_list":["post-3005","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-generic","tag-button","tag-cashapelayer","tag-cornerradius","tag-gravity","tag-layer","tag-scale","tag-swift","tag-uicollisionbehavior","tag-uidynamics","tag-uigravitybehavior","tag-uiview"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Swift - Circular button bubbles with gravity - while (true) {\u00a0}<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.albertopasca.it\/whiletrue\/swift-circular-button-bubbles-with-gravity\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Swift - Circular button bubbles with gravity - while (true) {\u00a0}\" \/>\n<meta property=\"og:description\" content=\"Today I want to show how to use the GravitySDK &#x1f680; (as discussed in the previous post) to make an animated bubbles buttons that falling around with gravity, like this:\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.albertopasca.it\/whiletrue\/swift-circular-button-bubbles-with-gravity\/\" \/>\n<meta property=\"og:site_name\" content=\"while (true) {\u00a0}\" \/>\n<meta property=\"article:published_time\" content=\"2021-11-26T08:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-11-27T15:40:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.38-1.png?fit=231%2C301\" \/>\n\t<meta property=\"og:image:width\" content=\"231\" \/>\n\t<meta property=\"og:image:height\" content=\"301\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Alberto Pasca\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@lupasca\" \/>\n<meta name=\"twitter:site\" content=\"@lupasca\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alberto Pasca\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-circular-button-bubbles-with-gravity\\\/#article\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-circular-button-bubbles-with-gravity\\\/\"},\"author\":{\"name\":\"Alberto Pasca\",\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"headline\":\"Swift &#8211; Circular button bubbles with gravity\",\"datePublished\":\"2021-11-26T08:30:00+00:00\",\"dateModified\":\"2021-11-27T15:40:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-circular-button-bubbles-with-gravity\\\/\"},\"wordCount\":265,\"publisher\":{\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"image\":{\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-circular-button-bubbles-with-gravity\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/www.albertopasca.it\\\/whiletrue\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.38-1.png?fit=231%2C301&ssl=1\",\"keywords\":[\"button\",\"cashapelayer\",\"cornerRadius\",\"gravity\",\"layer\",\"scale\",\"swift\",\"UICollisionBehavior\",\"uidynamics\",\"UIGravityBehavior\",\"uiview\"],\"articleSection\":[\"generic\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-circular-button-bubbles-with-gravity\\\/\",\"url\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-circular-button-bubbles-with-gravity\\\/\",\"name\":\"Swift - Circular button bubbles with gravity - while (true) {\u00a0}\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-circular-button-bubbles-with-gravity\\\/#primaryimage\"},\"image\":{\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-circular-button-bubbles-with-gravity\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/www.albertopasca.it\\\/whiletrue\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.38-1.png?fit=231%2C301&ssl=1\",\"datePublished\":\"2021-11-26T08:30:00+00:00\",\"dateModified\":\"2021-11-27T15:40:44+00:00\",\"breadcrumb\":{\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-circular-button-bubbles-with-gravity\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-circular-button-bubbles-with-gravity\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-circular-button-bubbles-with-gravity\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/www.albertopasca.it\\\/whiletrue\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.38-1.png?fit=231%2C301&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/www.albertopasca.it\\\/whiletrue\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.38-1.png?fit=231%2C301&ssl=1\",\"width\":231,\"height\":301,\"caption\":\"iOS bubble button circular gravity animated\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/swift-circular-button-bubbles-with-gravity\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Swift &#8211; Circular button bubbles with gravity\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#website\",\"url\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/\",\"name\":\"while (true) {\u00a0}\",\"description\":\"notes from a developer, tutorials, how-to, ideas\",\"publisher\":{\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\",\"name\":\"Alberto Pasca\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"caption\":\"Alberto Pasca\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\"},\"description\":\"Software engineer @ Pirelli &amp; C. S.p.A. with a strong passion for mobile \uf8ff development, security, and connected things.\",\"sameAs\":[\"https:\\\/\\\/www.albertopasca.it\",\"albertopasca\",\"https:\\\/\\\/x.com\\\/lupasca\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Swift - Circular button bubbles with gravity - while (true) {\u00a0}","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.albertopasca.it\/whiletrue\/swift-circular-button-bubbles-with-gravity\/","og_locale":"en_US","og_type":"article","og_title":"Swift - Circular button bubbles with gravity - while (true) {\u00a0}","og_description":"Today I want to show how to use the GravitySDK &#x1f680; (as discussed in the previous post) to make an animated bubbles buttons that falling around with gravity, like this:","og_url":"http:\/\/www.albertopasca.it\/whiletrue\/swift-circular-button-bubbles-with-gravity\/","og_site_name":"while (true) {\u00a0}","article_published_time":"2021-11-26T08:30:00+00:00","article_modified_time":"2021-11-27T15:40:44+00:00","og_image":[{"width":231,"height":301,"url":"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.38-1.png?fit=231%2C301","type":"image\/png"}],"author":"Alberto Pasca","twitter_card":"summary_large_image","twitter_creator":"@lupasca","twitter_site":"@lupasca","twitter_misc":{"Written by":"Alberto Pasca","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/www.albertopasca.it\/whiletrue\/swift-circular-button-bubbles-with-gravity\/#article","isPartOf":{"@id":"http:\/\/www.albertopasca.it\/whiletrue\/swift-circular-button-bubbles-with-gravity\/"},"author":{"name":"Alberto Pasca","@id":"http:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"headline":"Swift &#8211; Circular button bubbles with gravity","datePublished":"2021-11-26T08:30:00+00:00","dateModified":"2021-11-27T15:40:44+00:00","mainEntityOfPage":{"@id":"http:\/\/www.albertopasca.it\/whiletrue\/swift-circular-button-bubbles-with-gravity\/"},"wordCount":265,"publisher":{"@id":"http:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"image":{"@id":"http:\/\/www.albertopasca.it\/whiletrue\/swift-circular-button-bubbles-with-gravity\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.38-1.png?fit=231%2C301&ssl=1","keywords":["button","cashapelayer","cornerRadius","gravity","layer","scale","swift","UICollisionBehavior","uidynamics","UIGravityBehavior","uiview"],"articleSection":["generic"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/www.albertopasca.it\/whiletrue\/swift-circular-button-bubbles-with-gravity\/","url":"http:\/\/www.albertopasca.it\/whiletrue\/swift-circular-button-bubbles-with-gravity\/","name":"Swift - Circular button bubbles with gravity - while (true) {\u00a0}","isPartOf":{"@id":"http:\/\/www.albertopasca.it\/whiletrue\/#website"},"primaryImageOfPage":{"@id":"http:\/\/www.albertopasca.it\/whiletrue\/swift-circular-button-bubbles-with-gravity\/#primaryimage"},"image":{"@id":"http:\/\/www.albertopasca.it\/whiletrue\/swift-circular-button-bubbles-with-gravity\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.38-1.png?fit=231%2C301&ssl=1","datePublished":"2021-11-26T08:30:00+00:00","dateModified":"2021-11-27T15:40:44+00:00","breadcrumb":{"@id":"http:\/\/www.albertopasca.it\/whiletrue\/swift-circular-button-bubbles-with-gravity\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.albertopasca.it\/whiletrue\/swift-circular-button-bubbles-with-gravity\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.albertopasca.it\/whiletrue\/swift-circular-button-bubbles-with-gravity\/#primaryimage","url":"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.38-1.png?fit=231%2C301&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.38-1.png?fit=231%2C301&ssl=1","width":231,"height":301,"caption":"iOS bubble button circular gravity animated"},{"@type":"BreadcrumbList","@id":"http:\/\/www.albertopasca.it\/whiletrue\/swift-circular-button-bubbles-with-gravity\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/www.albertopasca.it\/whiletrue\/"},{"@type":"ListItem","position":2,"name":"Swift &#8211; Circular button bubbles with gravity"}]},{"@type":"WebSite","@id":"http:\/\/www.albertopasca.it\/whiletrue\/#website","url":"http:\/\/www.albertopasca.it\/whiletrue\/","name":"while (true) {\u00a0}","description":"notes from a developer, tutorials, how-to, ideas","publisher":{"@id":"http:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.albertopasca.it\/whiletrue\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"http:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac","name":"Alberto Pasca","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","caption":"Alberto Pasca"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g"},"description":"Software engineer @ Pirelli &amp; C. S.p.A. with a strong passion for mobile \uf8ff development, security, and connected things.","sameAs":["https:\/\/www.albertopasca.it","albertopasca","https:\/\/x.com\/lupasca"]}]}},"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2021\/11\/Simulator-Screen-Shot-iPhone-13-Pro-2021-11-23-at-09.35.38-1.png?fit=231%2C301&ssl=1","_links":{"self":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/3005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/comments?post=3005"}],"version-history":[{"count":25,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/3005\/revisions"}],"predecessor-version":[{"id":3080,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/3005\/revisions\/3080"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/media\/3036"}],"wp:attachment":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/media?parent=3005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/categories?post=3005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/tags?post=3005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}