在 SwiftUI (macOS) 中检查 Option-Key 的状态 [英] Check state of Option-Key in SwiftUI (macOS)

查看:22
本文介绍了在 SwiftUI (macOS) 中检查 Option-Key 的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来检查 macOS 上 SwiftUI 中选项键的状态.

I'm looking for a way to check the state of the option-key in SwiftUI on macOS.

即根据是否按下选项键,我想在 .onTapGesture 闭包中执行不同的操作.

I.e. depending on whether the option key is pressed or not I want to perform different actions in the .onTapGesture closure.

推荐答案

仅适用于 macOS 的 SwiftUI 具有 .modifiers 修饰符来指定 EventModifiers,因此您的情况如下所示下面的例子:

macOS-only SwiftUI has .modifiers modifier to specify EventModifiers, so your case is covered like in below example:

Rectangle()
    .fill(Color.yellow)
    .frame(width: 100, height: 40)
    .gesture(TapGesture().modifiers(.option).onEnded {
        print("Do anyting on OPTION+CLICK")
    })
    .onTapGesture {
        print("Do anyting on CLICK")
    }

这篇关于在 SwiftUI (macOS) 中检查 Option-Key 的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆