Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swiftui 快速幻灯片转换_Swiftui - Fatal编程技术网

Swiftui 快速幻灯片转换

Swiftui 快速幻灯片转换,swiftui,Swiftui,当用户点击错误的按钮时,我希望闪存卡 滑动到屏幕左侧,当用户点击正确的 按钮我希望闪存卡转换/滑动到 手表屏幕 我创建了一个最小可行的示例来向您展示一个可能的解决方案。看一看,告诉我是否能帮你更多的忙 struct Flashcard: View { @State var tangoID = randomNum @State var refreshToggle = false @State var showingSheet = false @State var bookmarke

当用户点击错误的按钮时,我希望闪存卡 滑动到屏幕左侧,当用户点击正确的 按钮我希望闪存卡转换/滑动到 手表屏幕

我创建了一个最小可行的示例来向您展示一个可能的解决方案。看一看,告诉我是否能帮你更多的忙

struct Flashcard: View {
  @State var tangoID = randomNum
  @State var refreshToggle = false
  @State var showingSheet = false
  @State var bookmarked = tangoArray[randomNum].bookmark
  @State public var showingNoMoreCardsSheet = false


  @State private var showResults: Bool = false
  @State private var fullRotation: Bool = false

  var body: some View {
    let zstack = ZStack {

      Frontside(id: $tangoID, sheet: $showingSheet, rotate: $fullRotation)
        .rotation3DEffect(.degrees(self.showResults ? 180.0 : 0.0), axis: (x: 0.0, y: 1.0, z: 0.0))
        .rotation3DEffect(.degrees(self.fullRotation ? 360.0 : 0.0), axis: (x: 0.0, y: 1.0, z: 0.0))
        .zIndex(self.showResults ? 0 : 1)


      Backside(id: $tangoID, sheet: $showingSheet, bookmark: $bookmarked, results: $showResults, rotate: $fullRotation)
        .rotation3DEffect(.degrees(self.showResults ? 0.0 : 180.0), axis: (x: 0.0, y: -1.0, z: 0.0))
        .rotation3DEffect(.degrees(self.fullRotation ? 360.0 : 0.0), axis: (x: 0.0, y: 1.0, z: 0.0))
        .zIndex(self.showResults ? 1 : 0)

    }
    .actionSheet(isPresented: $showingSheet) {
      ActionSheet(title: Text("Finished 終わり"), message: Text("お疲れさま! But feel free to keep going."), buttons: [.default(Text("はい"))]);
    }
    .onTapGesture {
      self.handleFlipViewTap()
    }
    .navigationBarTitle("Study")
    .contextMenu(menuItems: {Button(action: {
      tangoArray[randomNum].bookmark.toggle()
      database.updateUserData(tango: tangoArray[randomNum])
      self.fullRotation.toggle()
    }, label: {
      VStack{
        Image(systemName: tangoArray[randomNum].bookmark ? "bookmark" : "bookmark.fill")
          .font(.title)
        Text(tangoArray[randomNum].bookmark ? "Remove bookmark" : "Bookmark")
      }
    })
    })

    return zstack
  }



  private func handleFlipViewTap() -> Void
  {
    withAnimation(.linear(duration: 0.25))
    {
      self.showResults.toggle()
    }
  }
}
    public struct Frontside: View  
    {  
      @Binding public var id: Int  

      public var body: some View  
      {  
        ZStack{  


          RoundedRectangle(cornerRadius: 8, style: .continuous)    
            .frame(width: 140, height: 149)  
            .zIndex(0)  

          VStack {  
            Text(tangoArray[self.id].kanji)  

            .font(.system(size: 24))  


            .fontWeight(.regular)  
            .padding(25)  
            .lineLimit(3)   
            .zIndex(1)  

            Spacer()  
          }  

          VStack {  
            Spacer()  
            HStack {  

              Button(action: {  
                incorrect(i: self.id)  
                checkAttempts()  
                self.id = nextCard()   
              }) {  
                Image(systemName: "xmark")  
                  .font(.headline)  
                  .opacity(0.4)  

              }  

              Button(action: {  
                correct(i: self.id)  
                checkAttempts()  
                self.id = nextCard()   
              }) {  
                Image(systemName: "circle")  
                  .font(.headline)  
                  .opacity(0.4)  

              }  

            }  
          }  
          .zIndex(2)  
        }  
      }  
    }  

I have a view which is a flashcard. When the user taps on the incorrect button I want the flash card to slide to the left of the screen, and when the user taps on the correct button I want the flash card to transition/slide to the right of the watch screen. How do I do that?

谢谢,我能看到你在那里做什么。然而,我希望有一个快速的解决方案,使用.transition并移动到前缘或后缘。我只是不知道如何在我的代码中使用这些语句。@alamodey转换动画并不适合您的需要。它们用于在视图层次中创建和插入视图或从视图层次中删除视图时设置视图动画。如果必须移动视图,则不能使用过渡动画。您需要通常的简单动画。如果你能发布你的完整代码(以便我可以复制/粘贴),我很乐意进一步帮助你。我明白你的意思。我粘贴了更多的代码。我在这里问了另一个问题:它与我用来将内容保存到书签的上下文菜单有关。如果你也能就此提出建议,那就太好了。谢谢
struct ContentView: View {
    private let objWidth = CGFloat(100)
    private let objHeight = CGFloat(200)
    private let screenWidth = UIScreen.main.bounds.size.width;
    private let screenHeight = UIScreen.main.bounds.size.height;
    @State private var objOffset = CGFloat(50)

    var body: some View {
        VStack {
            Rectangle()
                .frame(width: objWidth, height: objHeight)
                .background(Color.black)
                .position(x: objOffset, y: (screenHeight-objHeight)/2.0)
            Button(action: {
                withAnimation{
                    self.move()
                }
            }) {
                Text("TAP")
            }
        }
    }

    private func move() {
        if objOffset > screenWidth/2.0 {
            objOffset = objWidth/2.0
        } else {
            objOffset = screenWidth-objWidth/2.0
        }
    }
}