我使用此方法以编程方式设置音量设备:
self.mpVolumeView.frame = CGRectMake(0, 0, self.view.bounds.width * 0.82, CGFloat(50))
self.mpVolumeView.showsRouteButton = false
self.mpVolumeView.showsVolumeSlider = true
self.mpVolumeView.backgroundColor = UIColor.clearColor()
for subview in self.mpVolumeView.subviews {
if (subview as UIView).description.rangeOfString("MPVolumeSlider") != nil {
// Set volume
volumeSlider = subview as UISlider
subview.setValue(0.5, animated: false)
break
}
}
这样可以正常工作,但每次设置滑块值时都会显示音量hud,有没有办法防止这种情况?
答案 0 :(得分:1)
你必须添加mpVolumeView作为主视图的子视图,并将alpha设置为0.000001,因为0因某些奇怪的原因不起作用:
view.addSubview(mpVolumeView)
mpVolumeView.alpha = 0.000001