微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用LongPressGesture多次触发操作

如何解决使用LongPressGesture多次触发操作

我想在使用TapGesture时触发一次动作,而在使用LongPressGesture时多次触发动作。我想做的最好的例子是键盘上的“删除”键,长按它会继续删除最后一个字符。

我的问题是如何在SwiftUI中复制此行为。

目前,我想出了这个解决方案(不起作用):

struct ContentView: View {
    var longPress: some Gesture {
        LongPressGesture(minimumDuration: 3)
            .onChanged({ (bool) in
                guard bool else {
                    self.timer?.invalidate()
                    return
                }
                
                self.timer =  Timer.scheduledTimer(withTimeInterval: 0.2,repeats: true) { (timer) in
                     action() // Fired every 0.2 seconds until the user stop pressing
                }
            })
    }
    
    @State var timer: Timer? = nil

    var body: some View {
        Subview()
            .onTapGesture {
                action() // Fired once
            }
            .gesture(longPress)
    }
}

解决方法

您可以尝试以下操作:

public function test(Request $request)
{
    
    dd($request->route()->parameters());
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。