Saturday, August 13, 2022
HomeiOS Developmentios - How do I add an motion to a SwiftUI view?

ios – How do I add an motion to a SwiftUI view?


As a result of I wish to use SwiftUI whereas concurrently supporting earlier iOS variations, I’ve needed to discover a completely different grid system. I’ve a easy design working, however I am unable to work out the way to do one thing with these views of mine. I’ve tried exhibiting alerts, including faucet gestures, nothing works. Am I simply making it out tougher than it must be?

Here is a picture of my interface, which is working tremendous, I simply can’t make these views to something! enter image description here

I primarily based my code off of this github repository: https://github.com/pietropizzi/GridStack/blob/grasp/Sources/GridStack/GridStack.swift

struct ContentView : View {
  let colours: [Color] = [.red, .green, .blue, .yellow, .purple]
  
  @State non-public var orientation = UIDeviceOrientation.unknown
  @State non-public var showAlert = false
  @State non-public var selectedShortcut: Int = 0 {
    didSet {
      showingHUD = false
    }
  }
  @State non-public var showingHUD = true
  
  var rows: CGFloat  orientation == .unknown ? 5 : 3
  var columns: CGFloat 
  
  var physique: some View {
    GeometryReader { proxy in
      GridStack(minCellWidth: (proxy.measurement.width / (columns + 1)), spacing: 6, numItems: 15) { index, cellWidth in
        CardView(iconName: "star.fill", title: "(index + 1)", description: "(# (index + 1))", width: cellWidth, peak: (proxy.measurement.peak / (rows)) - 7)
          .background(colours.randomElement())
          .cornerRadius(10)
          .onTapGesture {
            selectedShortcut = index
            showingHUD.toggle()
          }
      }
      if showingHUD {
        HUD {
          Label("Shortcut: (selectedShortcut)", systemImage: "star.fill")
        }
        .transition(AnyTransition.transfer(edge: .high).mixed(with: .opacity))
        .onAppear {
          DispatchQueue.principal.asyncAfter(deadline: .now() + 3) {
            withAnimation {
              showingHUD = false
            }
          }
        }
        .zIndex(1)
      }
    }.background(Coloration.rgba(crimson: 40, inexperienced: 40, blue: 40, alpha: 1))
      .statusBar(hidden: true)
  }
}

struct HUD<Content material: View>: View {
  @ViewBuilder let content material: Content material
  
  var physique: some View {
    content material
      .padding(.horizontal, 12)
      .padding(16)
      .background(
        Capsule()
          .foregroundColor(Coloration.white)
          .shadow(coloration: Coloration(.black).opacity(0.16), radius: 12, x: 0, y: 5)
      )
  }
}



struct CardView: View {
  var iconName: String
  var title: String
  var description: String
  var width: CGFloat
  var peak: CGFloat
  
  var physique: some View {
    VStack(alignment: .heart, spacing: 4) {
      Picture(systemName: iconName)
        .font(.system(measurement: 24))
        .padding(.high)
      VStack(alignment: .main, spacing: 2) {
        Textual content(description)
          .lineLimit(2)
          .multilineTextAlignment(.main)
      }
      .padding()
    }.foregroundColor(.white)
      .shadow(coloration: .darkGray, radius: 2, x: 2, y: 2)
      .body(minWidth: width, maxWidth: width, minHeight: peak, maxHeight: peak)
    //      .onTapGesture {
    //        Alert(title: Textual content("Alert Title"), message: Textual content("Message"))
    //      }
  }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments