How do you implement an MPVolumeView?

后端 未结 3 1134
刺人心
刺人心 2021-01-04 23:51

I want the user to be able to change the system volume with a slider, and I realized the only way to do this is with an MPVolumeView.

But I can\'t find any example c

3条回答
  •  离开以前
    2021-01-05 00:10

    In iOS 13 this has changed. Adding a slider in IB with its class set to MPVolumeView doesn't work anymore. So the accepted answer no longer works. The right way, as outlined in the Apple docs, is to use a UIView in IB and then in code add the MPVolumeView as a subview. Here's how in Swift:

    // myVolumeViewParentView is the UIView you put in IB
    let myVolumeView = MPVolumeView(frame: myVolumeViewParentView.bounds)
    myVolumeViewParentView.addSubview(myVolumeView)
    

    This method works in iOS 12 too.

提交回复
热议问题