iOS-如何在Swift中显示"AirPlay"弹出菜单? [英] iOS - How can I display an 'AirPlay' popup menu in Swift?

查看:92
本文介绍了iOS-如何在Swift中显示"AirPlay"弹出菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Swift项目中显示AirPlay弹出菜单?(像Spotify这样的许多应用程序都可以显示以下内容):

How can I display an AirPlay popup menu in my Swift project? (Many applications like Spotify can display one like below):

推荐答案

毕竟,似乎没有简单,直接的方法来使自定义按钮显示系统的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:

这篇关于iOS-如何在Swift中显示"AirPlay"弹出菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆