只有用户在SwiftUI中将手指放在屏幕上时,什么手势才能执行代码?

问题描述 投票:0回答:1

仅当用户将手指放在屏幕上时,哪种手势才能执行代码?

运行某些代码不应该是原因(手势)的影响,我想要的是在用户将手指放在屏幕上的同时运行某些代码,并且如果用户将手指从代码上移开则停止运行

例如,

//some view
.unknownGesture{
// running this code only while user placing their finger on the screen
}
swiftui uigesturerecognizer
1个回答
0
投票

这里是可能的解决方法

.gesture(
  DragGesture(minimumDistance: 0)
    .onChanged() { event in
      print(">>> activated")
    })
© www.soinside.com 2019 - 2024. All rights reserved.