Created
June 7, 2019 22:20
-
-
Save b3ll/04d4ff998eaa90ba22472e2090a587b6 to your computer and use it in GitHub Desktop.
"unstable" Swift UI Animation in Xcode 11 b1
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 | |
// CircleLine | |
// | |
// Created by Adam Bell on 6/5/19. | |
// Copyright © 2019 Adam Bell. All rights reserved. | |
// | |
import SwiftUI | |
struct ContentView : View { | |
@GestureState var dragTranslation: CGSize = .zero | |
@GestureState var translations: [CGSize] = Array<CGSize>(repeating: .zero, count: 10) | |
var body: some View { | |
let dragGesture = DragGesture(minimumDistance: 0) | |
.updating($translations) { (dragGesture, translations, transaction) in | |
translations.insert(dragGesture.translation, at: 0) | |
translations.removeLast() | |
} | |
return ZStack { | |
ForEach((0..<translations.count).reversed()) { index in | |
return Circle() | |
.frame(width: 50, height: 50, alignment: .center) | |
.foregroundColor(.blue) | |
.offset(x: self.translations.count > 0 ? self.translations[index].width : 0, y: self.translations.count > 0 ? self.translations[index].height : 0) | |
.gesture(index == 0 ? dragGesture : nil) | |
.animation(index != 0 ? Animation.fluidSpring().delay(0.1 * Double(index)) : nil) | |
} | |
} | |
} | |
} | |
#if DEBUG | |
struct ContentView_Previews : PreviewProvider { | |
static var previews: some View { | |
return ContentView() | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment