Closed Meffi29a closed 5 years ago
I have the same issue here.
Nice to know that i`m not the only one. So maybe it is a reason for the Team to have a short view on this.
I found a workaround, maybe You can use it too. As You could know, the density on IOS is 3 (on the new Retinas), so i tried to enlarge the Content from the Surface by 3 by do a NEGATIVE margin... It worked exact! so i decided to do it generic to all iOS. I used DeviceDisplay.ScreenMetrics (Xamarin.Essentials who is in beta.) to scale the MyUrhoSurface.Margin to a negative Value who is 1/Density from the current Display. But this is not working when your App change landscape to portrait and then Back. then there is an offset on topp-padding after changing orientation. Im Tired to find a solution for this, so i blocked portrait on iOS for now. Maybe someone find the ?bug? in the source, ore find a better workaround as i did. But You should calculate with your surfaces current with and heigh, as you have no Fullscreen at your shown app.
#####################################################################
public partial class MainPage : ContentPage
{
public static UrhoSurface MyUrhoSurface;
public MainPage()
{
MyUrhoSurface = new UrhoSurface
{
BackgroundColor = Xamarin.Forms.Color.BlanchedAlmond,
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
};
MyUrhoSurface.Show<Views.UrhoObjects.MySurfaceContentPage>(new ApplicationOptions("Data")
{
Orientation = ApplicationOptions.OrientationType.LandscapeAndPortrait,
});
MyUrhoSurface.HorizontalOptions = LayoutOptions.FillAndExpand;
MyUrhoSurface.VerticalOptions = LayoutOptions.FillAndExpand;
var stack = new StackLayout();
stack.Children.Add(MyUrhoSurface);
Content = stack;
Content.HorizontalOptions = LayoutOptions.FillAndExpand;
Content.VerticalOptions = LayoutOptions.FillAndExpand;
SizeChanged += OnSizeChanged;
InitializeComponent();
}
void OnSizeChanged(object sender, EventArgs e)
{
if (!Device.RuntimePlatform.Equals(Device.iOS)) return;
var top = 0-(DeviceDisplay.ScreenMetrics.Height / DeviceDisplay.ScreenMetrics.Density);
var bottom = top;
var left = 0-(DeviceDisplay.ScreenMetrics.Width / DeviceDisplay.ScreenMetrics.Density);
var right = left;
Debug.WriteLine($"Top: {top} Bottom: {bottom} Left: {left} Right: {right}");
MyUrhoSurface.Margin = new Thickness(left, top, right, bottom);
}
}
####################################################
I seem to have found a solution that works for me.
Remove SizeChanged += OnSizeChanged;
Put
MyUrhoSurface.Show<Views.UrhoObjects.MySurfaceContentPage>(new ApplicationOptions("Data") { Orientation = ApplicationOptions.OrientationType.LandscapeAndPortrait, });
Into a function, let's say it will be
CastUrho();
inside of your public partial class MainPage : ContentPage
protected override void OnAppearing() { CastUrho(); }
inside of your public partial class MainPage : ContentPage
Try this method, I hope it helps.
Thanks DeadEndKing!
Is working on iOS nearly 100%
When the orientation switching from portrait to landscape and back its still buggy. The height is set false, and so i have to add:
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
//Debug.WriteLine($"width: {width} height: {height}");
if (!Device.RuntimePlatform.Equals(Device.iOS) && DeviceDisplay.ScreenMetrics.Orientation != ScreenOrientation.Landscape) return;
MyUrhoSurface.LayoutTo(new Rectangle(new Point(0, 0), new Size(width, height)));
}
At least, your solution works great. I have to think about the reasons, but think it should not be as it works now. Xamarin.Forms uses sometimes the Resolution of the Device, but when uncomment the //Debug, it's to see, that sometimes the resolution / density is used instead.
Reason to highlight as bug?
Hello, i start working on UrhoSharp 2017, had a lot of trouble to get it work as i need, but struggle since days on one little thing. And i start to run in circles by trying to find the wrong place in my code! I tried a lot of setup on iOS, for fixing an strange behavior, only on iOS. To my Code: I build an .Forms App with a Surface. Insert my Urho-Stuff (For this example the example "public class Charts : Application" = from the tutorial.
And when i start on:
is there an issue with the 3xDensity in iOS? On Android-Tabelet with 1.5 Density its working
Xamarin.Forms : 3.1.0.697729 UrhoSharp.Forms: 1.8.93 VisualStudio for Mac 7.6.3 I included Xamarin.Essentials 0.10.0 too, but not used for this example.
I think, all the newest version
My Code:
AppDeligate: as out of the Box
global::Xamarin.Forms.Forms.Init(); LoadApplication(new App()); return base.FinishedLaunching(app, options);
MainPage in Core-Code: (//-Stuff dose not change anything)
public partial class MainPage : ContentPage {
public UrhoSurface MyUrhoSurface { get; set;} public MainPage() {
MainPage.Xaml: only the<...>
As you see, the result is not fine, but only on iOS.
Maybe one of You know what to do. Someone has the same problems? Maybe its a issue, not done by myself, but so it could be known and there could be a workaround. But i did not find a comment belonging to this.