Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从Xamarin中的代码推送新页面后如何旋转屏幕_C#_Xamarin_Xamarin.forms_Youtube_Youtube Api - Fatal编程技术网

C# 从Xamarin中的代码推送新页面后如何旋转屏幕

C# 从Xamarin中的代码推送新页面后如何旋转屏幕,c#,xamarin,xamarin.forms,youtube,youtube-api,C#,Xamarin,Xamarin.forms,Youtube,Youtube Api,标题说的差不多,我正在推一个包含视频源的网络视图 Witch有一个youtube视频嵌入HTML代码。 一旦按下按钮,我需要强制它进入全屏模式。 这是我正在使用的一段代码,如果您有其他/更好的方法,请回答 我是新手,所以请对我放松:) 我搜索了一些关于这个主题的信息,但我找不到在按下屏幕时只在一页上旋转屏幕的方法 public partial class MainScreen : TabbedPage { public HtmlWebViewSource Vide

标题说的差不多,我正在推一个包含视频源的网络视图 Witch有一个youtube视频嵌入HTML代码。 一旦按下按钮,我需要强制它进入全屏模式。 这是我正在使用的一段代码,如果您有其他/更好的方法,请回答

我是新手,所以请对我放松:)

我搜索了一些关于这个主题的信息,但我找不到在按下屏幕时只在一页上旋转屏幕的方法

    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
        }
    }

公共部分类主屏幕:选项卡页
{
公共HtmlWebViewSource视频源{get;set;}
私有常量字符串PlayerHTML=@”
";
已单击专用异步void ImageButton(对象发送方,事件参数e)
{
VideoSource=新的HtmlWebViewSource
{
Html=PlayerHTML
};
var a=新内容页
{
Content=newwebview()
{
源=视频源
}
};
NavigationPage.SetHasNavigationBar(a,false);
等待导航。PushAsync(a);
//以某种方式使屏幕旋转
}
}
我期望有两种解决方案

  • Xamarin相关解决方案,如通过到达MainActivity.cs旋转屏幕
  • 一个HTML/YouTube嵌入解决方案,比如在视频链接中强制全屏启动视频

  • 您可以使用消息中心来处理此问题 在Android上:

       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");
    
        }