[英]How to Implement accessibilityCustomActions for VoiceOver on Mac?
我有一個按鈕可以響應各種鼠標單擊(常規單擊、右鍵單擊、控制+單擊、選項+單擊、命令+單擊...)以顯示不同的彈出菜單。 由於 VoiceOver 用戶使用實際的物理鼠標會很煩人,我想將它們映射到不同的 VoiceOver 操作。
但是,我沒有得到我預期的結果。 有人可以幫助我更好地理解我所缺少的嗎? 這是我目前發現的。
如果我NSButton
並覆蓋以下函數,它們就可以正常工作。 除了有一件奇怪的事情。 如果我按 vo+command+space 調出可用操作列表,VoiceOver 會顯示 Action 1 而不是 Show Menu。
override func accessibilityPerformPress() -> Bool {
print("Pressed!")
return true
}
override func accessibilityPerformShowAlternateUI() -> Bool {
print("Show Alternate UI")
return true
}
override func accessibilityPerformShowMenu() -> Bool {
print("Show Menu")
return true
}
在同一個NSButton
子類中,如果我還覆蓋了accessibilityCustomActions
函數,當我按下 vo+command+space 時,“做某事”永遠不會出現在可用操作列表中。
override func accessibilityCustomActions() -> [NSAccessibilityCustomAction]? {
let custom = NSAccessibilityCustomAction(name: "Do Something", target: self, selector: #selector(doSomething))
return [custom]
}
@objc func doSomething() -> Bool {
print("Done something.")
return true
}
如果我NSView
而不是NSButton
,並覆蓋 #1 中的相同功能,一切正常。 與第一種情況不同,即使 VoiceOver 也正確地為來自accessibilityPerformShowMenu
的操作說“顯示菜單”,而不是“操作 1”。
在同一個NSView
子類中,如果我覆蓋accessibilityCustomActions
以及accessibilityPerformPress
、 accessibilityPerformShowMenu
或accessibilityPerformShowAlternateUI
,“做某事”不會出現在動作列表中。
但是,如果我只是在沒有accessibilityPerformPress
、 accessibilityPerformShowMenu
和accessibilityPerformShowAlternateUI
情況下accessibilityPerformPress
覆蓋accessibilityCustomActions
,“做某事”確實會出現在操作列表中。
我嘗試創建另一個名為“Press”的動作,它在按下 vo+space 時做同樣的事情,並包括在accessibilityCustomActions
的返回值中。 但是,Vo+space 並沒有觸發該動作。 相反,我必須按 vo+command+space,然后選擇“按”。 我猜這個動作只有一個名字“Press”,但它實際上並沒有連接到 vo+space。 我不確定如何才能真正做出特定的自定義操作來響應 vo+space。
如果有人可以幫助我將accessibilityCustomActions
以及accessibilityPerformPress
、 accessibilityPerformShowMenu
和accessibilityPerformShowAlternateUI
一起實現到NSButton
,我將不勝感激。
非常感謝!
問題是您在NSButton
上覆蓋了這些 AX 方法,而不是NSButtonCell
。 對於幾乎所有與NSControl
的可訪問性有關的事情,您都需要處理有問題的NSCell
。 如果您使用上面編寫的自定義操作代碼並將其粘貼到按鈕使用的NSButtonCell
子類中,那么它將起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.