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

TestProject.zip
0.15MB

▶ 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">
    <StackLayout
        HorizontalOptions="Center"
        VerticalOptions="Center">
        <Button x:Name="rotateButton"
            HorizontalOptions="Center"
            Text="텍스트 회전" />
        <Label x:Name="label"
            HorizontalOptions="Center"
            Margin="0,100,0,0"
            FontSize="18"
            Text="버튼을 누르고 있으면 됩니다." />
    </StackLayout>
</ContentPage>

 

728x90

 

▶ MainPage.xaml.cs

using Microsoft.Maui.Dispatching;
using System.Diagnostics;

namespace TestProject;

/// <summary>
/// 메인 페이지
/// </summary>
public partial class MainPage : ContentPage
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Field
    ////////////////////////////////////////////////////////////////////////////////////////// Private

    #region Field

    /// <summary>
    /// 타이머
    /// </summary>
    private IDispatcherTimer timer;

    /// <summary>
    /// 스톱워치
    /// </summary>
    private Stopwatch stopwatch = new Stopwatch();

    #endregion

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

    #region 생성자 - MainPage()

    /// <summary>
    /// 생성자
    /// </summary>
    public MainPage()
    {
        InitializeComponent();

        this.timer = Dispatcher.CreateTimer();

        this.timer.Interval = TimeSpan.FromMilliseconds(16);

        this.rotateButton.Pressed  += rotateButton_Pressed;
        this.rotateButton.Released += rotateButton_Released;
        this.timer.Tick            += timer_Tick;
    }

    #endregion

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

    #region 회전 버튼 PRESS 처리하기 - rotateButton_Pressed(sender, e)

    /// <summary>
    /// 회전 버튼 PRESS 처리하기
    /// </summary>
    /// <param name="sender">이벤트 발생자</param>
    /// <param name="e">이벤트 인자</param>
    private void rotateButton_Pressed(object sender, EventArgs e)
    {
        this.stopwatch.Start();

        this.timer.Start();
    }

    #endregion
    #region 회전 버튼 RELEASE 처리하기 - rotateButton_Released(sender, e)

    /// <summary>
    /// 회전 버튼 RELEASE 처리하기
    /// </summary>
    /// <param name="sender">이벤트 발생자</param>
    /// <param name="e">이벤트 인자</param>
    private void rotateButton_Released(object sender, EventArgs e)
    {
        this.stopwatch.Stop();

        this.timer.Stop();
    }

    #endregion
    #region 타이머 틱 처리하기 - timer_Tick(sender, e)

    /// <summary>
    /// 타이머 틱 처리하기
    /// </summary>
    /// <param name="sender">이벤트 발생자</param>
    /// <param name="e">이벤트 인자</param>
    private void timer_Tick(object sender, EventArgs e)
    {
        this.label.Rotation = 360 * (this.stopwatch.Elapsed.TotalSeconds % 1);
    }

    #endregion
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요