UICommandAlternate

https://developer.apple.com/documentation/uikit/uicommandalternate

"An object representing an alternative action for a command."

명령에 대한 대안 액션을 나타내는 객체입니다.

Declaration

@MainActor class UICommandAlternate : NSObject

Overview

명령에 대한 대안 액션을 제공하고자 한다면, UICommandAlternate 객체를 생성하고 UICommand 혹은 UIKeyCommand 객체에 생성한 객체를 추가하시기 바랍니다. 명령 대안은 modifierFlags 속성에서 구체화된 컨트롤 혹은 옵션 키와 같은 키보드 수정키를 누를 때 사용이 가능합니다.

예를 들어 앱은 키 명령과 함께 생성된 리로드 메뉴를 가질 것이며, 이 메뉴는 커맨드 R 단축키를 가질 것입니다. 사용자가 리로드를 선택하거나 키보드에서 커맨드 R을 누르면, 앱은 현재 윈도우에 표시된 데이터를 리로드합니다. 그러나 앱은 하나 이상의 윈도우를 표시할 수도 잇습니다. 이 경우 현재 하나가 아닌 모든 윈도우의 데이터를 리로드하는 것을 포함하게 됩니다.

전체 리로드 명령은 사용자가 옵션 키를 누를 때 전체 리로드가 사용 가능하도록 만들어주는 modifierFlags 속성에 대안을 구체화합니다. 전체 리로드를 선택하려면 사용자는 리로드를 초함하는 메뉴를 표시하는 동안 옵션 키를 누르고 있을 수 있습니다. 이는 리로드 메뉴를 전체 리로드로 교체합니다. 또한, 사용자는 옵션 커맨드 R을 눌러 전체 리로드를 선택할 수도 있습니다.

// Create an alternate for the reload command. The alternative command appears
// in the menu system when the user holds down the keys specified in `modifierFlags`.
let reloadAlternate = UICommandAlternate(title: "Reload All",
                                         action: #selector(reloadAllData(_:)),
                                         modifierFlags: [.alternate])

// Create a selector-based action with a keyboard shortcut to use as a menu element.
let reloadCommand = UIKeyCommand(title: "Reload",
                                action: #selector(reloadData(_:)),
                                input: "r",
                                modifierFlags: [.command],
                                alternates: [reloadAlternate])

// Use the .displayInline option to avoid displaying the menu as a submenu,
// and to separate it from the other menu elements using a line separator.
let reloadMenuItem = UIMenu(title: "", options: .displayInline, children: [reloadCommand])

// Insert the menu into the File menu before the Close menu.
builder.insertSibling(reloadMenuItem, beforeMenu: .close)

좋은 웹페이지 즐겨찾기