当contextMenu出现时,我试图延迟,因为我有一个拖动手势,当我尝试拖动时会出现这种意外延迟。
…
Text(exampleText)
.contextMenu
{
delay()
// Menus here
}
.gesture(
DragGesture()
.onEnded(
{ end in
switch exampleTextAlignment
{
case .leading:
if end.translation.width > 0
{
exampleTextAlignment = .center
}
case .center:
if end.translation.width < 0
{
exampleTextAlignment = .leading
}
else if end.translation.width > 0
{
exampleTextAlignment = .trailing
}
case .trailing:
if end.translation.width < 0
{
exampleTextAlignment = .center
}
}
}
)
)
…
…其中 delay() 是:
…
private func delay() async {
try? await Task.sleep(nanoseconds: UInt64(secondsHere * Double(NSEC_PER_SEC)))
hasTimeElapsed = true
}
…
预期结果。
Xcode v.13.2和 iOS v.15.2。