Skip to content

Instantly share code, notes, and snippets.

@PaulWoodIII
Created September 2, 2019 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulWoodIII/1a74952e7590b52a872a4749bfbbb966 to your computer and use it in GitHub Desktop.
Save PaulWoodIII/1a74952e7590b52a872a4749bfbbb966 to your computer and use it in GitHub Desktop.
Little SwiftUI animation to fill the screen with red circle from the center of the screen
//
// ContentView.swift
// ExplosionView
//
// Created by Paul Wood on 9/2/19.
// Copyright © 2019 Paul Wood. All rights reserved.
//
import SwiftUI
struct ContentView: View {
@State var willExplode = false
struct ExplosionCircle: View {
let proxy: GeometryProxy
@Binding var willExplode: Bool
var maximumTranslation: CGFloat {
let centerPoint = CGPoint(x: proxy.size.width/2, y: proxy.size.height/2)
let h = sqrt( centerPoint.y * centerPoint.y + centerPoint.x + centerPoint.x)
let minimum = min(proxy.size.width, proxy.size.height)
return h / minimum
}
var body: some View {
Circle()
.foregroundColor(Color.red)
.scaleEffect(self.willExplode ? maximumTranslation : 0.0)
.animation(.easeInOut(duration: 1.0))
.aspectRatio(1, contentMode: .fill)
.onAppear{
self.willExplode = true
}
}
}
var body: some View {
GeometryReader { proxy in
ExplosionCircle(proxy: proxy,
willExplode: self.$willExplode)
}.edgesIgnoringSafeArea(.all)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment