实现设备定位逻辑(使用插件,例如:https://github.com/aliozgur/Xamarin.Plugins/tree/master/DeviceOrientation或自己使用依赖服务实现),然后:
protected override void OnAppearing()
{
base.OnAppearing();
_RotatePage();
SizeChanged += _SizeChanged;
}
protected override void OnDisappearing()
{
SizeChanged -= _SizeChanged;
base.OnDisappearing();
}
private void _SizeChanged(object sender, EventArgs e)
{
var svc = DependencyService.Get<IDeviceOrientationService>();
var orientation = svc.GetOrientation();
NavigationPage.SetHasNavigationBar(this, orientation == DeviceOrientation.Portrait);
}