Created
September 2, 2019 17:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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