如何在应用程序中打开/关闭airplay镜像?

时间:2017-09-06 10:51:57

标签: airplay mirroring

我为on/off airplay镜像编写代码,但它在应用程序中无法使用。

请任何人帮助我如何在应用程序中获取airplay镜像事件。

参考下面的代码:

func addBarBtn() 
{

    let aButton: UIButton = UIButton(type: .custom)
    aButton.frame = CGRect(x: 0, y: 0, width: 80, height: 25)
    aButton.setImage(UIImage(named: "Img"), for: .normal)
    aButton.addTarget(self, action:#selector(ViewController.showAirplay), for: .touchUpInside)
    let aBarButtonItem: UIBarButtonItem = UIBarButtonItem(customView: aButton)

    self.navigationItem.rightBarButtonItem = aBarButtonItem
}

func showAirplay() 
{

   let rect = CGRect(x: -100, y: 0, width: 0, height: 0)

   let airplayVolume = MPVolumeView(frame: rect)

   airplayVolume.showsVolumeSlider = true

   self.view.addSubview(airplayVolume)

   for view: UIView in airplayVolume.subviews {

   if let button = view as? UIButton {

   button.sendActions(for: .touchUpInside)

   break

  } 

}

airplayVolume.removeFromSuperview()

 }

0 个答案:

没有答案