У меня есть щепотка, чтобы увеличить изображение. Хотя он и работает, он кажется неуклюжим и неестественным, особенно когда вы его панорамируете. Я не могу использовать контейнер панорамирования с функцией сжатия, так как мое решение использует для рисования одно касание, поэтому оно должно сохранять сжатие.
Повсюду есть примеры контейнеров сжатия от Microsoft, и независимо от того, как я его настраиваю, оно никогда не будет похоже на приложение для фотографий для iOS.
Я создал репозиторий в качестве примера приложения.
/>https://github.com/AustinOberholtzer/MauiPinchZoom
Будем очень благодарны за любую помощь!
public class PinchContainer : ContentView
{
private double currentScale = 1;
private double startScale = 1;
private double xOffset;
private double yOffset;
public PinchContainer()
{
var pinchGesture = new PinchGestureRecognizer();
pinchGesture.PinchUpdated += OnPinchUpdated;
GestureRecognizers.Add(pinchGesture);
}
private void OnPinchUpdated(object? sender, PinchGestureUpdatedEventArgs e)
{
if (e.Status == GestureStatus.Started)
{
startScale = Content.Scale;
Content.AnchorX = 0;
Content.AnchorY = 0;
}
if (e.Status == GestureStatus.Running)
{
// Calculate the scale factor to be applied.
currentScale += (e.Scale - 1) * startScale;
currentScale = Math.Max(1, currentScale);
// The ScaleOrigin is in relative coordinates to the wrapped user interface element,
// so get the X pixel coordinate.
var renderedX = Content.X + xOffset;
var deltaX = renderedX / Width;
var deltaWidth = Width / (Content.Width * startScale);
var originX = (e.ScaleOrigin.X - deltaX) * deltaWidth;
// The ScaleOrigin is in relative coordinates to the wrapped user interface element,
// so get the Y pixel coordinate.
var renderedY = Content.Y + yOffset;
var deltaY = renderedY / Height;
var deltaHeight = Height / (Content.Height * startScale);
var originY = (e.ScaleOrigin.Y - deltaY) * deltaHeight;
// Calculate the transformed element pixel coordinates.
var targetX = xOffset - ((originX * Content.Width) * (currentScale - startScale));
var targetY = yOffset - ((originY * Content.Height) * (currentScale - startScale));
// Apply translation based on the change in origin.
Content.TranslationX = Math.Clamp(targetX, -Content.Width * (currentScale - 1), 0);
Content.TranslationY = Math.Clamp(targetY, -Content.Height * (currentScale - 1), 0);
// Apply scale factor
Content.Scale = currentScale;
}
if (e.Status == GestureStatus.Completed)
{
// Store the translation delta's of the wrapped user interface element.
xOffset = Content.TranslationX;
yOffset = Content.TranslationY;
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/780 ... pplication
Ощущение естественности. Увеличьте масштаб приложения на острове Мауи. ⇐ IOS
Программируем под IOS
1769559425
Anonymous
У меня есть щепотка, чтобы увеличить изображение. Хотя он и работает, он кажется неуклюжим и неестественным, особенно когда вы его панорамируете. Я не могу использовать контейнер панорамирования с функцией сжатия, так как мое решение использует для рисования одно касание, поэтому оно должно сохранять сжатие.
Повсюду есть примеры контейнеров сжатия от Microsoft, и независимо от того, как я его настраиваю, оно никогда не будет похоже на приложение для фотографий для iOS.
Я создал репозиторий в качестве примера приложения.
/>https://github.com/AustinOberholtzer/MauiPinchZoom
Будем очень благодарны за любую помощь!
public class PinchContainer : ContentView
{
private double currentScale = 1;
private double startScale = 1;
private double xOffset;
private double yOffset;
public PinchContainer()
{
var pinchGesture = new PinchGestureRecognizer();
pinchGesture.PinchUpdated += OnPinchUpdated;
GestureRecognizers.Add(pinchGesture);
}
private void OnPinchUpdated(object? sender, PinchGestureUpdatedEventArgs e)
{
if (e.Status == GestureStatus.Started)
{
startScale = Content.Scale;
Content.AnchorX = 0;
Content.AnchorY = 0;
}
if (e.Status == GestureStatus.Running)
{
// Calculate the scale factor to be applied.
currentScale += (e.Scale - 1) * startScale;
currentScale = Math.Max(1, currentScale);
// The ScaleOrigin is in relative coordinates to the wrapped user interface element,
// so get the X pixel coordinate.
var renderedX = Content.X + xOffset;
var deltaX = renderedX / Width;
var deltaWidth = Width / (Content.Width * startScale);
var originX = (e.ScaleOrigin.X - deltaX) * deltaWidth;
// The ScaleOrigin is in relative coordinates to the wrapped user interface element,
// so get the Y pixel coordinate.
var renderedY = Content.Y + yOffset;
var deltaY = renderedY / Height;
var deltaHeight = Height / (Content.Height * startScale);
var originY = (e.ScaleOrigin.Y - deltaY) * deltaHeight;
// Calculate the transformed element pixel coordinates.
var targetX = xOffset - ((originX * Content.Width) * (currentScale - startScale));
var targetY = yOffset - ((originY * Content.Height) * (currentScale - startScale));
// Apply translation based on the change in origin.
Content.TranslationX = Math.Clamp(targetX, -Content.Width * (currentScale - 1), 0);
Content.TranslationY = Math.Clamp(targetY, -Content.Height * (currentScale - 1), 0);
// Apply scale factor
Content.Scale = currentScale;
}
if (e.Status == GestureStatus.Completed)
{
// Store the translation delta's of the wrapped user interface element.
xOffset = Content.TranslationX;
yOffset = Content.TranslationY;
}
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78086459/natural-feeling-pinch-to-zoom-in-maui-application[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия