ios 扫码枪外设 键盘模式_iOS使用UIKeyCommand监听外接键盘按键事件

本文介绍了如何在iOS应用中使用UIKeyCommand来监听和响应外接扫码枪或其他硬件键盘的按键事件。通过重写keyCommands属性并创建UIKeyCommand对象,可以设置不同按键及组合键的输入和响应方法。尽管部分按键和组合键在系统层无法监听,但该方法能有效处理如方向键、空格、回车等常见键位。
摘要由CSDN通过智能技术生成

keyCommands

Declaration

@interface UIResponder (UIResponderKeyCommands)

@property (nullable,nonatomic,readonly) NSArray *keyCommands NS_AVAILABLE_IOS(7_0); // returns an array of UIKeyCommand objects<

@end

Discussion

A responder object that supports hardware keyboard commands can redefine this property and use it to return an array of UIKeyCommand objects that it supports. Each key command object represents the keyboard sequence to recognize and the action method of the responder to call in response.

The key commands you return from this method are applied to the entire responder chain. When an key combination is pressed that matches a key command object, UIKit walks the responder chain looking for an object that implements the corresponding action method. It calls that method on the first object it finds and then stops processing the event.

实例代码

@inter

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值