Это может быть ошибка в самой .NET Maui, но я не уверен. (в Xamarin.Forms положение сетки сбрасывается в середину экрана.)
Есть ли обходной путь или способ решить эту проблему?
ОБНОВЛЕНИЕ: нажатие кнопки при увеличенной сетке также перемещает позицию прокрутки и изменяет высоту прокрутки.
Просмотр после уменьшения масштаба:
Вот код ниже, чтобы воспроизвести проблему:
MainPage.xaml
Код: Выделить всё
Код: Выделить всё
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MauiAppTest
{
public class ZoomableScrollView : ScrollView
{
}
}
Код: Выделить всё
using Microsoft.Maui.Handlers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 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);
}
}
}
Код: Выделить всё
using Microsoft.Extensions.Logging;
#if IOS
using MauiAppTest.Platforms.iOS;
#endif
namespace MauiAppTest
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.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.Build();
}
}
}
Я пробовал, в том числе:
・Использование ScrollViewRenderer (с использованием maui.compatibility)
・Попробовал получить ZoomScale и ContentOffset во время OnSleep, а затем установить их снова во время OnResume.
ОБНОВЛЕНИЕ: вот код в Xamarin.Forms
ZoomableScrollView.cs (Пользовательский ScrollView)
Код: Выделить всё
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
namespace TestXamarin
{
public class ZoomableScrollView : ScrollView
{
}
}
Код: Выделить всё
using Foundation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TestXamarin;
using TestXamarin.iOS;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(ZoomableScrollView), typeof(ZoomableScrollViewRenderer))]
namespace TestXamarin.iOS
{
public class ZoomableScrollViewRenderer : ScrollViewRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
var test = this.Element as ZoomableScrollView;
this.MinimumZoomScale = 1f;
this.MaximumZoomScale = 3f;
this.ViewForZoomingInScrollView += (UIScrollView sv) => { return this.Subviews[0]; };
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/778 ... ew-for-ios
Мобильная версия