첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
4.04MB

▶ PanContentView.cs

namespace TestProject;

/// <summary>
/// 패닝 컨텐트 뷰
/// </summary>
public class PanContentView : ContentView
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Field
    ////////////////////////////////////////////////////////////////////////////////////////// Private

    #region Field

    /// <summary>
    /// 현재 X
    /// </summary>
    private double currentX;
    
    /// <summary>
    /// 현재 Y
    /// </summary>
    private double currentY;

    #endregion

    //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 생성자 - PanContentView()

    /// <summary>
    /// 생성자
    /// </summary>
    public PanContentView()
    {
        PanGestureRecognizer recognizer = new PanGestureRecognizer();

        recognizer.PanUpdated += recognizer_PanUpdated;

        GestureRecognizers.Add(recognizer);
    }

    #endregion

    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Private

    #region 인식기 패닝 업데이트시 처리하기 - recognizer_PanUpdated(sender, e)

    /// <summary>
    /// 인식기 패닝 업데이트시 처리하기
    /// </summary>
    /// <param name="sender">이벤트 발생자</param>
    /// <param name="e">이벤트 인자</param>
    private void recognizer_PanUpdated(object sender, PanUpdatedEventArgs e)
    {
        switch(e.StatusType)
        {
            case GestureStatus.Running :

                Content.TranslationX = Math.Max(Math.Min(0, this.currentX + e.TotalX), -Math.Abs(Content.Width  - DeviceDisplay.MainDisplayInfo.Width ));
                Content.TranslationY = Math.Max(Math.Min(0, this.currentY + e.TotalY), -Math.Abs(Content.Height - DeviceDisplay.MainDisplayInfo.Height));

                break;

            case GestureStatus.Completed :

                this.currentX = Content.TranslationX;
                this.currentY = Content.TranslationY;

                break;
        }
    }

    #endregion
}

 

728x90

 

▶ MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="TestProject.MainPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:TestProject">
    <AbsoluteLayout>
        <local:PanContentView>
            <Image Source="source.png"
                WidthRequest="1920"
                HeightRequest="1280" />
        </local:PanContentView>
    </AbsoluteLayout>
</ContentPage>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요