标题说得差不多了,我正在推送一个包含 VideoSource 的 WebView
女巫有一个 youtube 视频嵌入 HTML 代码。
一旦它被插入,我需要强制它进入全屏模式。
这是我正在使用的一段代码,如果您有任何其他/更好的方法,请回答
我是新手所以请放轻松:)
我在这个主题上搜索了一下,但无论如何我都找不到在插入屏幕时仅在 1 页上旋转屏幕。
public partial class MainScreen : TabbedPage
{
public HtmlWebViewSource VideoSource { get; set; }
private const string PlayerHTML = @"<html>
<body>
<iframe style='position: absolute; top: 0; left: 0; width: 100%; height: 100%;'
src='https://www.youtube.com/embed/6e7qKcVigQo?rel=0?autoplay=1?modestbranding=1'
frameborder='0'
allow='accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture'
allowfullscreen>
</iframe>
</body>
</html>";
private async void ImageButton_Clicked(object sender, EventArgs e)
{
VideoSource = new HtmlWebViewSource
{
Html = PlayerHTML
};
var a = new ContentPage
{
Content = new WebView()
{
Source = VideoSource
}
};
NavigationPage.SetHasNavigationBar(a, false);
await Navigation.PushAsync(a);
//make the screen rotate SOMEHOW
}
}
我期望有两种解决方案;
最佳答案
您可以使用消息中心来处理
在安卓上:
protected override void OnCreate(Bundle savedInstanceState)
{
Current = this;
//TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Xamarin.Forms.Forms.Init(this, savedInstanceState);
//allowing the device to change the screen orientation based on the rotation
MessagingCenter.Subscribe<VideoPlayerView>(this, "allowLandScape", sender =>
{
RequestedOrientation = ScreenOrientation.Landscape;
});
//during page close setting back to portrait
MessagingCenter.Subscribe<VideoPlayerView>(this, "preventLandScape", sender =>
{
RequestedOrientation = ScreenOrientation.Portrait;
});
LoadApplication(new App());
}
叫那个
protected override void OnAppearing()
{
base.OnAppearing();
MessagingCenter.Send(this, "allowLandScape");
}
//during page close setting back to portrait
protected override void OnDisappearing()
{
base.OnDisappearing();
MessagingCenter.Send(this, "preventLandScape");
}
关于c# - 从 Xamarin 中的代码推送新页面后如何旋转屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57732259/