自定义 UILongPressGestureRecognizer 的问题不适用于 VoiceOver
Issues with custom UILongPressGestureRecognizer not Working with VoiceOver
当 VoiceOver 为 运行 时,我无法让自定义长按处理程序正常工作。
在下面的自定义 UITableViewCell 代码中,我添加了一个带有 UITableViewCell 的长按手势识别器,并在长按时调用 handleVoiceOverLongPress()
。
// called when this custom UITableViewCell class is initialized
func initializeVoiceoverCellView() {
NotificationCenter.default.addObserver(self,
selector: #selector(voiceOverStatusChanged),
name: UIAccessibility.voiceOverStatusDidChangeNotification,
object: nil)
if UIAccessibility.isVoiceOverRunning {
addLongPressGestureRecognizer(withTarget: self, action: #selector(handleVoiceOverLongPress), duration: 1.0)
}
}
@objc func voiceOverStatusChanged() {
if UIAccessibility.isVoiceOverRunning {
addLongPressGestureRecognizer(withTarget: self, action: #selector(handleVoiceOverLongPress), duration: 1.0)
} else {
removeLongPressGestureRecognizer()
}
}
使用上面的代码,handleVoiceOverLongPress()
在 VoiceOver 打开时长按时永远不会被调用。我尝试了一次长按,然后
I'm having issues getting a custom long press handler to work when VoiceOver is running.
尝试使用下面的代码实现对您的长按手势 table 查看单元格:
//Gesture definition in your cell implementation for instance.
var yourLongPressGesture: UILongPressGestureRecognizer
yourLongPressGesture = UILongPressGestureRecognizer(target: self,
action: #selector(handleVoiceOverLongPress))
yourLongPressGesture.minimumPressDuration = 0.5
yourLongPressGesture.delaysTouchesBegan = true
yourLongPressGesture.delegate = yourCell
yourCell.addGestureRecognizer(yourLongPressGesture)
//Define what the long press triggers in the following function.
@objc func handleVoiceOverLongPress(gestureReconizer: UILongPressGestureRecognizer) {
if gestureReconizer.state == UIGestureRecognizer.State.ended {
print("LONG PRESS ENDED")
}
else {
print("LONG PRESS IN PROGRESS...")
}
}
不要忘记 long press in the VoiceOver world 与不具备此功能的那个不一样 运行:双击并按住压力 得到相同的结果,这很重要。
遵循以上代码片段的基本原理应该可以帮助您使 UILongPressGestureRecognizer 与 VoiceOver 一起工作。
当 VoiceOver 为 运行 时,我无法让自定义长按处理程序正常工作。
在下面的自定义 UITableViewCell 代码中,我添加了一个带有 UITableViewCell 的长按手势识别器,并在长按时调用 handleVoiceOverLongPress()
。
// called when this custom UITableViewCell class is initialized
func initializeVoiceoverCellView() {
NotificationCenter.default.addObserver(self,
selector: #selector(voiceOverStatusChanged),
name: UIAccessibility.voiceOverStatusDidChangeNotification,
object: nil)
if UIAccessibility.isVoiceOverRunning {
addLongPressGestureRecognizer(withTarget: self, action: #selector(handleVoiceOverLongPress), duration: 1.0)
}
}
@objc func voiceOverStatusChanged() {
if UIAccessibility.isVoiceOverRunning {
addLongPressGestureRecognizer(withTarget: self, action: #selector(handleVoiceOverLongPress), duration: 1.0)
} else {
removeLongPressGestureRecognizer()
}
}
使用上面的代码,handleVoiceOverLongPress()
在 VoiceOver 打开时长按时永远不会被调用。我尝试了一次长按,然后
I'm having issues getting a custom long press handler to work when VoiceOver is running.
尝试使用下面的代码实现对您的长按手势 table 查看单元格:
//Gesture definition in your cell implementation for instance.
var yourLongPressGesture: UILongPressGestureRecognizer
yourLongPressGesture = UILongPressGestureRecognizer(target: self,
action: #selector(handleVoiceOverLongPress))
yourLongPressGesture.minimumPressDuration = 0.5
yourLongPressGesture.delaysTouchesBegan = true
yourLongPressGesture.delegate = yourCell
yourCell.addGestureRecognizer(yourLongPressGesture)
//Define what the long press triggers in the following function.
@objc func handleVoiceOverLongPress(gestureReconizer: UILongPressGestureRecognizer) {
if gestureReconizer.state == UIGestureRecognizer.State.ended {
print("LONG PRESS ENDED")
}
else {
print("LONG PRESS IN PROGRESS...")
}
}
不要忘记 long press in the VoiceOver world 与不具备此功能的那个不一样 运行:双击并按住压力 得到相同的结果,这很重要。
遵循以上代码片段的基本原理应该可以帮助您使 UILongPressGestureRecognizer 与 VoiceOver 一起工作。