I am at present making an attempt to create a customized ScrollViewer that has a zoom and pan performance however each time the display screen’s zoomed and the app resumes from a sleep state, the view modifications its place, shrinks its ScrollHeight , and zooming out positions the grid on the higher left of the display screen. (Check with the screenshot beneath.)
It might be a bug in .NET Maui itself however I am unsure. (on Xamarin.Types it really works)
Is there a work-around or a approach to resolve it?
This is the code beneath to breed the issue:
MainPage.xaml
<?xml model="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:MauiAppTest"
x:Class="MauiAppTest.MainPage">
<controls:ZoomableScrollView>
<Grid Background="pink">
<VerticalStackLayout
Padding="30,0"
Spacing="25">
<Picture
Supply="dotnet_bot.png"
HeightRequest="185"
Facet="AspectFit"
SemanticProperties.Description="dot web bot in a race automobile quantity eight" />
<Label
Textual content="Howdy, World!"
Model="{StaticResource Headline}"
SemanticProperties.HeadingLevel="Level1" />
<Label
Textual content="Welcome to .NET Multi-platform App UI"
Model="{StaticResource SubHeadline}"
SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Welcome to dot web Multi platform App U I" />
<Button
x:Identify="CounterBtn"
Textual content="Click on me"
SemanticProperties.Trace="Counts the variety of occasions you click on"
Clicked="OnCounterClicked"
HorizontalOptions="Fill" />
</VerticalStackLayout>
</Grid>
</controls:ZoomableScrollView>
</ContentPage>
ZoomableScrollView.cs (Customized ScrollView)
utilizing System;
utilizing System.Collections.Generic;
utilizing System.Linq;
utilizing System.Textual content;
utilizing System.Threading.Duties;
namespace MauiAppTest
{
public class ZoomableScrollView : ScrollView
{
}
}
ZoomableScrollViewHandler.cs
utilizing Microsoft.Maui.Handlers;
utilizing System;
utilizing System.Collections.Generic;
utilizing System.Linq;
utilizing System.Textual content;
utilizing System.Threading.Duties;
utilizing UIKit;
namespace MauiAppTest.Platforms.iOS
{
public class ZoomableScrollViewHandler : ScrollViewHandler
{
protected override void ConnectHandler(UIScrollView platformView)
{
base.ConnectHandler(platformView);
if(platformView != null)
{
platformView.MinimumZoomScale = 1;
platformView.MaximumZoomScale = 3;
platformView.ViewForZoomingInScrollView += (UIScrollView sv) =>
{
return platformView.Subviews[0];
};
}
}
protected override void DisconnectHandler(UIScrollView platformView)
{
base.DisconnectHandler(platformView);
}
}
}
MauiProgram.cs
utilizing Microsoft.Extensions.Logging;
#if IOS
utilizing MauiAppTest.Platforms.iOS;
#endif
namespace MauiAppTest
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Common.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
#if IOS
builder.ConfigureMauiHandlers(handlers =>
handlers.AddHandler(typeof(ZoomableScrollView),typeof(ZoomableScrollViewHandler)));
#endif
#if DEBUG
builder.Logging.AddDebug();
#endif
return builder.Construct();
}
}
}
I anticipated that the ScrollViewer would work with out drawback because it labored on Xamarin.Types.
Issues I’ve tried together with:
・Utilizing a ScrollViewRenderer(with using maui.compatibility)
・Tried getting the ZoomScale and ContentOffset throughout OnSleep, then setting them once more throughout OnResume.