简体   繁体   English

如何使用帮助UISlider快速更改iOS音量

[英]How to change ios volume in swift with help UISlider

I wrote the following code, but it doesn't change iOS System Volume, it only changes the sound from within the app. 我编写了以下代码,但它不会更改iOS系统音量,只会更改应用程序中的声音。 audioPlayer is subclass of AVAudioPlayer audioPlayerAVAudioPlayer子类

   @IBAction func sliderVol(sender: UISlider) {
        audioPlayer.volume = sender.value
    }

The UISlider has the sent event of value changed UISlider的值已发送事件已更改
How can I change iOS system volume with help UISlider ? 如何使用帮助UISlider更改iOS系统音量?

The MPVolumeView class is designed to let you do exactly this. MPVolumeView类旨在让您完全做到这一点。 It's in MediaPlayer framework. 它在MediaPlayer框架中。 So, add that to your app to make things build correctly. 因此,请将其添加到您的应用中以使构建正确。

You create it and make it visible the way you instantiate any other subclass of UIView , which you probably know by now. 您创建它并以实例化UIView任何其他子类的方式使其可见,您现在可能已经知道了。

You can provide your own frame and use this to change the system volume. 您可以提供自己的框架,并以此来更改系统音量。

var wrapperView = UIView(frame: CGRectMake(30, 200, 260, 20))
self.view.backgroundColor = UIColor.clearColor()
self.view.addSubview(wrapperView)

// 3
var volumeView = MPVolumeView(frame: wrapperView.bounds)
wrapperView.addSubview(volumeView)

For more help you can look here Controlling system volume using swift 如需更多帮助,请点击此处使用swift控制系统音量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM