0
처음에는 메인 페이지을 표시 한 다음 버튼을 클릭하고 두 번째 페이지으로 전화하십시오. 아무 것도 보이지 않지만 뒤로 버튼을 클릭하면 표시 방향이 세로 방향이어야하지만 가로 방향으로 세로 방향과 같은 이상한 동작이 발생합니다. > 페이지 2 (오른쪽 가로 방향) -> (뒤로 버튼 동작) ->페이지 1 (잘못된 세로 방향)가로 방향으로 한 페이지에서 세로로 다른 페이지로 돌아올 때의 문제
when firstly showing when click back button
0.
MainPage :
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
async void OnTapGestureRecognizerTapped(object sender, EventArgs args)
{
var fullScreenVideoPage = new SecondPage();
NavigationPage.SetHasNavigationBar(fullScreenVideoPage, false);
await Navigation.PushAsync(fullScreenVideoPage);
}
protected override void OnAppearing()
{
base.OnAppearing();
MessagingCenter.Send(this, "preventLandScape");
}
}
XAML (MainPage)
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:App1"
x:Class="App1.MainPage"
BackgroundColor="Black">
<StackLayout x:Name="stackLayout" Orientation="Horizontal">
<Image Source="icon.png"
WidthRequest="150"
HeightRequest="150"
HorizontalOptions ="CenterAndExpand"
VerticalOptions="CenterAndExpand">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="OnTapGestureRecognizerTapped" />
</Image.GestureRecognizers>
</Image>
</StackLayout>
</ContentPage>
SecondPage :
public partial class SecondPage : ContentPage
{
public SecondPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
MessagingCenter.Send(this, "showLandscapeOrientation");
}
protected override void OnDisappearing()
{
base.OnDisappearing();
MessagingCenter.Send(this, "showPortraitOrientation");
}
async void OnTapGestureRecognizerTapped(object sender, EventArgs args)
{
await Navigation.PushAsync(new NavigationPage(new MainPage()));
}
}
MainAc tivity :
[Activity(Label = "App1", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
//allowing the device to change the screen orientation based on the rotation
MessagingCenter.Subscribe<SecondPage>(this, "showLandscapeOrientation", sender =>
{
RequestedOrientation = ScreenOrientation.Landscape;
});
//during page close setting back to portrait
MessagingCenter.Subscribe<SecondPage>(this, "preventLandScape", sender =>
{
RequestedOrientation = ScreenOrientation.Portrait;
});
MessagingCenter.Subscribe<MainPage>(this, "showPortraitOrientation", sender =>
{
RequestedOrientation = ScreenOrientation.Portrait;
});
}
}