更新时间:2023-02-17 14:56:59
毕竟,似乎没有简单,直接的方法来使自定义按钮显示系统的Airplay菜单.
After all it seems there is no easy and straightforward way to make a custom button display the system's Airplay menu.
但是,@ totiG指向我一个有趣的资源,我创建了一个脚本,该脚本在屏幕可见区域之外创建了标准的音量控制,并模拟了对Airplay按钮的点击:
However, @totiG pointer me to an interesting resource and I created a script that creates the standard Volume Control outside of the visible area of the screen a simulates a click on the Airplay button:
func showAirplay() {
let rect = CGRect(x: -100, y: 0, width: 0, height: 0)
let airplayVolume = MPVolumeView(frame: rect)
airplayVolume.showsVolumeSlider = false
self.view.addSubview(airplayVolume)
for view: UIView in airplayVolume.subviews {
if let button = view as? UIButton {
button.sendActions(for: .touchUpInside)
break
}
}
airplayVolume.removeFromSuperview()
}
运行此代码后,将出现以下弹出菜单:
After running this code the following popup menu appears: