相关疑难解决方法(0)

如何使用SwiftUI在列表中滑动以编辑动作?

我正在尝试使用SwiftUI实现滑动以编辑动作。删除动作和移动动作都可以很好地工作,但是我不知道如何启用滑动来编辑动作。

当用户将激活滑动以进行编辑操作时,我想打开编辑屏幕。

这是我的代码:

struct TableView : View {
@State var dataSource = DataSource()

var body: some View {
        NavigationView {
            List {
                ForEach(dataSource.pokemons.identified(by: \.id)) { pokemon in
                    Text(pokemon.name) 
                }
                .onDelete(perform: deletePokemon)
                .onMove(perform: movePokemon)
            }
            .navigationBarItems(leading: EditButton(), trailing: Button(action: addPokemon, label: { Text("Add") }))
            .navigationBarTitle(Text("Pokemons"))
        }
}
Run Code Online (Sandbox Code Playgroud)

xcode ios swift swiftui

8
推荐指数
1
解决办法
743
查看次数

SwiftUI:多点触控手势/多个手势

SwiftUI 中是否可以同时跟踪多个手势?我希望我的一个主视图能够同时跟踪多个手指拖动。

ZStack {
    Color.black
      .edgesIgnoringSafeArea(.all)
      .gesture(DragGesture(minimumDistance: 0)
               .onChanged { (value) in
                 //some logic
               }.onEnded { (value) in
                  //more logic         
               })
       //other code
}
Run Code Online (Sandbox Code Playgroud)

我有这个代码,但是我一次只能处理一个拖动手势。如果一个手指在拖动,然后我尝试添加另一个手指,第一个停止。

我试图实现多个手指同时在屏幕上的效果。每个手指同时拖动一个圆圈(一个圆圈跟随每个手指)。

我在 Apple 的文档中看到了同步手势,但这是指一个手势触发多个块。

multi-touch gesture swiftui

8
推荐指数
1
解决办法
2294
查看次数

如何在SwiftUI中检测点击手势位置?

(对于SwiftUI,不是普通的UIKit)非常简单的示例代码,例如,在灰色背景上显示红色框:

struct ContentView : View {
    @State var points:[CGPoint] = [CGPoint(x:0,y:0), CGPoint(x:50,y:50)]
    var body: some View {
        return ZStack {
            Color.gray
                .tapAction {
                   // TODO: add an entry to self.points of the location of the tap
                }
            ForEach(self.points.identified(by: \.debugDescription)) {
                point in
                Color.red
                    .frame(width:50, height:50, alignment: .center)
                    .offset(CGSize(width: point.x, height: point.y))
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我假设不是需要tapAction,而是需要TapGesture或其他东西?但即使在那儿,我也看不到任何方法来获取有关水龙头位置的信息。我将如何处理?

swift swiftui

5
推荐指数
7
解决办法
1456
查看次数

SwiftUI-列表中的自定义滑动动作

如何在SwiftUI中使用自定义滑动动作?

我试图使用UIKit框架使它们在SwiftUI中工作。但这对我不起作用。

import SwiftUI
import UIKit



    init() {
        override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
            let important = importantAction(at: indexPath)
            return UISwipeActionsConfiguration(actions: [important])
        }
        func importantAction(at indexPath: IndexPath) -> UIContextualAction {
            let action = UIContextualAction(style: .normal, title: "Important") { (action, view, completion) in
                print("HI")
            }
            action.backgroundColor = UIColor(hue: 0.0861, saturation: 0.76, brightness: 0.94, alpha: 1.0) /* #f19938 */
            action.image = UIImage(named: "pencil")
            return action
        }
    }






struct TestView: View {

      NavigationView {
               List {
                    ForEach(appointmentsViewModel.appointments.identified(by: \.id)) …
Run Code Online (Sandbox Code Playgroud)

list swipe swift swiftui

5
推荐指数
3
解决办法
1308
查看次数

标签 统计

swiftui ×4

swift ×3

gesture ×1

ios ×1

list ×1

multi-touch ×1

swipe ×1

xcode ×1