在MPVolumeView中隐藏卷HUD视图

时间:2018-01-03 04:48:00

标签: ios swift mpvolumeview

我使用MPVolumeViewUISlider来控制我的设备音频,下面是我的代码:

extension MPVolumeView {
    var volumeSlider: UISlider {
        self.showsRouteButton = false
        self.showsVolumeSlider = true

        var slider = UISlider()
        for subview in self.subviews {
            if subview.isKind(of: UISlider.self){
                slider = subview as! UISlider
                slider.isContinuous = false
                slider.minimumTrackTintColor = UIColor.outlineStrokeColor
                slider.setThumbImage(#imageLiteral(resourceName: "volume"), for: .normal)
                slider.maximumTrackTintColor = UIColor.lightGray
                (subview as! UISlider).value = AVAudioSession.sharedInstance().outputVolume
                return slider
            }
        }
        return slider
    }
}


let mpVolumeView: MPVolumeView = {
    let view = MPVolumeView()
    return view
}()

override func viewDidLoad() { 
    _ = mpVolumeView.volumeSlider
    view.addSubview(mpVolumeView)
}

一切都很好但每当我打开我的应用程序时,音量HUD会出现并在几秒钟后消失。之后它不会再出现,但我希望有一个选项可以随时隐藏它。我试图将MPVolumeView的框架设置为.zero,但它仍然不起作用。有没有办法可以这样做?

sample image

0 个答案:

没有答案