【发布时间】:2019-06-17 19:21:41
【问题描述】:
我想捕捉可访问性焦点的变化。
我搜索并尝试了accessibilityElementDidBecomeFocused,但在光标更改后没有触发。我想为按钮添加值,并在光标更改后删除此值。
我的代码是这样的:
override func viewDidLoad() {
flashButton.accessibilityLabel = "Change the flash status"
flashButton.accessibilityTraits = [.button]
flashButton.accessibilityIdentifier = "flashButton"
}
@IBAction func flashButtonTapped(_ sender: Any) {
var currentFlashStatus = "off"
guard let device = AVCaptureDevice.default(AVCaptureDevice.DeviceType.builtInWideAngleCamera, for: AVMediaType.video, position: .back) else { return }
guard device.hasTorch else { return }
do {
try device.lockForConfiguration()
if device.torchMode == .on {
device.torchMode = .off
flashButton.image = UIImage(named: "flashOffIcon")
currentFlashStatus = "off"
} else {
do {
try device.setTorchModeOn(level: 1.0)
flashButton.image = UIImage(named: "flashOnIcon")
currentFlashStatus = "on"
} catch {
print(error)
}
}
device.unlockForConfiguration()
} catch {
print(error)
}
flashButton.accessibilityLabel = "Turned \(currentFlashStatus) the flash"
}
首先,它显示“更改闪光灯状态”,如果我双击它会显示“打开闪光灯状态”,这是正确的。
如果我改变光标并回到闪光按钮,它应该说再次改变闪光状态。但它说“打开闪光灯状态”
我怎样才能做到这一点?
【问题讨论】:
标签: ios swift accessibility