共用方式為


UIViewController.AddKeyCommand(UIKeyCommand) 方法

定義

新增 command 為連結硬體鍵盤可用的快捷方式。

[Foundation.Export("addKeyCommand:")]
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 9, 0, ObjCRuntime.PlatformArchitecture.All, null)]
public virtual void AddKeyCommand (UIKit.UIKeyCommand command);
abstract member AddKeyCommand : UIKit.UIKeyCommand -> unit
override this.AddKeyCommand : UIKit.UIKeyCommand -> unit

參數

command
UIKeyCommand

新鍵盤動作的定義。

屬性

備註

UIKeyCommand 物件只會與附加的硬體鍵盤一起產生。

若要建立鍵盤快速鍵,開發人員必須建立 Selector 與具有適當 ExportAttribute 類型 Action<UIKeyCommand> 之方法相關聯的 :

[Export("NewFileAccelerator:")]
void NewFileAccelerator(UIKeyCommand cmd)
{
   //etc...
}

public override void ViewDidLoad ()
{
    base.ViewDidLoad ();

    var actionSelector = new Selector("NewFileAccelerator:");
    accelerator = UIKeyCommand.Create((NSString) "N", UIKeyModifierFlags.Command, actionSelector);

    AddKeyCommand(accelerator);
}

適用於