zoukankan      html  css  js  c++  java
  • Windows Phone 7 旋转动画(RotateTransform)

          所谓旋转动画(RotateTransform)也就是一个元素以一个坐标点为旋转中心点旋转,在使用旋转动画(RotateTransform)的时候需要注意的有两点:旋转中心点(Center)和旋转角度(Angle)。

    小例子设置了一个按照角度变化旋转,一个按照时间变化来旋转

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <Grid.RowDefinitions>
    <RowDefinition Height="*" />
    <RowDefinition Height="*" />
    <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <TextBlock Grid.Row="0"
    Text
    ="Frame-Based"
    FontSize
    ="{StaticResource PhoneFontSizeLarge}"
    HorizontalAlignment
    ="Center"
    VerticalAlignment
    ="Center"
    RenderTransformOrigin
    ="0.5 0.5">
    <TextBlock.RenderTransform>
    <RotateTransform x:Name="rotate1" />
    </TextBlock.RenderTransform>
    </TextBlock>

    <TextBlock Grid.Row="1"
    Text
    ="Time-Based"
    FontSize
    ="{StaticResource PhoneFontSizeLarge}"
    HorizontalAlignment
    ="Center"
    VerticalAlignment
    ="Center"
    RenderTransformOrigin
    ="0.5 0.5">
    <TextBlock.RenderTransform>
    <RotateTransform x:Name="rotate2" />
    </TextBlock.RenderTransform>
    </TextBlock>

    <Button Grid.Row="2"
    Content
    ="暂停 5 秒"
    HorizontalAlignment
    ="Center"
    Click
    ="OnButtonClick" />
    </Grid>
    using System;
    using System.Threading;
    using System.Windows;
    using System.Windows.Media;
    using Microsoft.Phone.Controls;

    namespace FrameBasedVsTimeBased
    {
    public partial class MainPage : PhoneApplicationPage
    {
    DateTime startTime;

    public MainPage()
    {
    InitializeComponent();

    startTime
    = DateTime.Now;
    CompositionTarget.Rendering
    += OnCompositionTargetRendering;
    //当此事件发生时,表示存在一个可视框架可用于呈现到 Silverlight 内容图面。
    //然后,可以在处理程序中一帧一帧地修改应用程序的可视对象或任何其他方面的内容
    }

    void OnCompositionTargetRendering(object sender, EventArgs args)
    {
    // Frame-based
    rotate1.Angle = (rotate1.Angle + 0.2) % 360;//设置顺时针旋转角度

    // Time-based
    TimeSpan elapsedTime = DateTime.Now - startTime;
    rotate2.Angle
    = (elapsedTime.TotalMinutes * 360) % 360;
    }
    //暂停5秒
    void OnButtonClick(object sender, RoutedEventArgs args)
    {
    Thread.Sleep(
    5000);
    }
    }
    }
  • 相关阅读:
    PHP开发APP接口(九)
    C#深入理解类型
    C#从委托、lambda表达式到linq总结
    C# ==和Equals()
    C# 泛型
    C# Reflection
    原声JS网络请求
    JavaScript预编译
    泛型初探
    C#内存分配
  • 原文地址:https://www.cnblogs.com/linzheng/p/1961840.html
Copyright © 2011-2022 走看看