我已经制作了一个自定义渲染器来在xamarin.forms应用程序中渲染MPVolumeView。每当我调整音量时,我都会在屏幕上看到这个阻止屏幕上内容的大系统HUD。看起来像这样:
如何删除此内容?这是我的自定义渲染器:
public class AudioOutputViewRenderer : ViewRenderer<AudioOutputView, UIView>
{
MPVolumeView view;
protected override void OnElementChanged(ElementChangedEventArgs<AudioOutputView> e)
{
base.OnElementChanged(e);
TintColor = UIColor.FromRGB(54, 66, 94);
if (Control == null)
{
view = new MPVolumeView()
{
ShowsRouteButton = false,
ShowsVolumeSlider = true
};
SetNativeControl(view);
}
}
}
答案 0 :(得分:1)
我听不懂AudioOutputViewRenderer
但是要隐藏MPVolumeView
,则需要下一步:
在您的IosProject中-> AppDelegate
->方法FinishedLaunching
添加下一个代码
var volumeView = new MPVolumeView(new CGRect(-1000,0,0,0));// -1000 will hide your view from user
volumeView.ClipsToBounds = true;
var slider = volumeView.Subviews.First(x => x is UISlider) as UISlider;
UIApplication.SharedApplication.KeyWindow.RootViewController.View.AddSubview(volumeView);
在您可以使用var slider
来更改音量之后
slider.Value = [your vlm];