相关疑难解决方法(0)

SwiftUI:ListItem 手势

Target 是具有以下行为的修改:

在此处输入图片说明

(但只有 2 个按钮 - 左侧 1 个,右侧 1 个)

行为:

  • 短滑显示按钮并让用户能够点击它。

  • 强长滑动按下按钮。

  • 能够使用 2 指手势


最小可重现示例:

import SwiftUI

public extension View {
    func SwiperizeItem(closureL: @escaping () -> (), closureR: @escaping () -> ()) -> some View
    {
        self.modifier( SwiperizeItemModifier(closureL: closureL, closureR: closureR) )
    }
}

struct SwiperizeItemModifier: ViewModifier {
    @State var dragOffset = CGSize.zero
    
    @State var offset1Shown = CGSize(width: 100, height: 0)
    @State var offset1Click = CGSize(width: 250, height: 0)
    
    @State var offset2Shown = CGSize(width: -100, height: 0) …
Run Code Online (Sandbox Code Playgroud)

macos swift swiftui

9
推荐指数
2
解决办法
1711
查看次数

如何在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
查看次数

标签 统计

swift ×2

swiftui ×2

macos ×1