Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. struct ContentView: View {
  2. @State var showOverlay = false
  3. @State var curColor = Color.blue
  4.  
  5. var body: some View {
  6. Text("Hello World")
  7. .frame(width: 100, height: 100)
  8. .background(curColor)
  9. .cornerRadius(20)
  10. .onTapGesture { self.showOverlay.toggle() }
  11. .overlay( ArcSelectionView(isShowing: self.$showOverlay, curColor: self.$curColor) )
  12. }
  13. }
  14.  
  15. struct ArcSelectionView: View {
  16. @Binding var isShowing : Bool
  17. @Binding var curColor : Color
  18.  
  19. let colors = [Color.blue, Color.red, Color.green, Color.yellow]
  20.  
  21. var body: some View {
  22. ZStack {
  23. ForEach(1 ..< 5, id: \.self) { item in
  24. Circle()
  25. .trim(from: self.isShowing ? CGFloat((Double(item) * 0.25) - 0.25) : CGFloat(Double(item) * 0.25),
  26. to: CGFloat(Double(item) * 0.25))
  27. .stroke(self.colors[item - 1], lineWidth: 30)
  28. .frame(width: 300, height: 300)
  29. .animation(.linear(duration: 0.4))
  30. .onTapGesture {
  31. self.curColor = self.colors[item - 1]
  32. self.isShowing.toggle()
  33. }
  34. }
  35. }
  36. .opacity(self.isShowing ? 1 : 0)
  37. .rotationEffect(.degrees(self.isShowing ? 0 : 180))
  38. .animation(.linear(duration: 0.5))
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement