如何检测 RPSystemBroadcastPickerView 何时被点击
How to detect when the RPSystemBroadcastPickerView is tapped
我正在使用 RPSystemBroadcastPickerView
从我的应用程序开始系统范围的屏幕录制。 RPSystemBroadcastPickerView
在开始录制和一切方面是完全自主的,我想这是有道理的 - 只有用户可以通过明确点击按钮来开始屏幕录制。
我需要知道 RPSystemBroadcastPickerView
何时被点击。现在 UI 正在显示键盘,我想继续显示它(它是一个聊天应用程序)。但是,显示广播扩展列表以选择一个的表格显示在键盘下方。见下图:
这有效地阻止了用户开始广播。如果我知道用户何时点击 RPSystemBroadcastPickerView
,我可以在那一刻手动隐藏键盘。有什么建议吗?
我没有找到任何回调,但您可以创建透明按钮,将其添加到 RPSystemBroadcastPickerView 上方。当用户点击您的按钮时,您将能够隐藏键盘,而不是使用代码将操作转移到 RPSystemBroadcastPickerView:
for subview in screenSharingProviderPickerView.subviews {
if let button = subview as? UIButton {
button.sendActions(for: UIControlEvents.allTouchEvents)
}
}
我找到了与已接受答案类似的解决方案,但您不需要创建透明按钮。
我只是在选择器按钮调度 table 中添加了额外的 target-action 对,当按下按钮时 #selector
将被触发。
/// picker is an instance of RPSystemBroadcastPickerView
for subviews in picker.subviews {
if let button = subviews as? UIButton {
button.addTarget(self, action: #selector(pickerAction), for: .touchUpInside)
}
}
/// You can also accept _ sender: UIButton as parameter, if you need to.
@objc func pickerAction() {
/// called when user press on RPSystemBroadcastPickerView
}
Note: Keep in mind that, if Apple change hierarchy of this view in the future, you probably need to update application as well.
我正在使用 RPSystemBroadcastPickerView
从我的应用程序开始系统范围的屏幕录制。 RPSystemBroadcastPickerView
在开始录制和一切方面是完全自主的,我想这是有道理的 - 只有用户可以通过明确点击按钮来开始屏幕录制。
我需要知道 RPSystemBroadcastPickerView
何时被点击。现在 UI 正在显示键盘,我想继续显示它(它是一个聊天应用程序)。但是,显示广播扩展列表以选择一个的表格显示在键盘下方。见下图:
这有效地阻止了用户开始广播。如果我知道用户何时点击 RPSystemBroadcastPickerView
,我可以在那一刻手动隐藏键盘。有什么建议吗?
我没有找到任何回调,但您可以创建透明按钮,将其添加到 RPSystemBroadcastPickerView 上方。当用户点击您的按钮时,您将能够隐藏键盘,而不是使用代码将操作转移到 RPSystemBroadcastPickerView:
for subview in screenSharingProviderPickerView.subviews {
if let button = subview as? UIButton {
button.sendActions(for: UIControlEvents.allTouchEvents)
}
}
我找到了与已接受答案类似的解决方案,但您不需要创建透明按钮。
我只是在选择器按钮调度 table 中添加了额外的 target-action 对,当按下按钮时 #selector
将被触发。
/// picker is an instance of RPSystemBroadcastPickerView
for subviews in picker.subviews {
if let button = subviews as? UIButton {
button.addTarget(self, action: #selector(pickerAction), for: .touchUpInside)
}
}
/// You can also accept _ sender: UIButton as parameter, if you need to.
@objc func pickerAction() {
/// called when user press on RPSystemBroadcastPickerView
}
Note: Keep in mind that, if Apple change hierarchy of this view in the future, you probably need to update application as well.