Basic Animations

本文深入探讨了Xamarin.Forms中创建基本动画的方法,包括视图平移、旋转和缩放等效果,帮助开发者实现更丰富的用户交互体验。
摘要由CSDN通过智能技术生成
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="BasicAnimationsSample.MainPage">
    <Grid Margin="{OnPlatform iOS='0,30,0,0'}">
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Image x:Name="Image1" Source="bridge.jpeg" MinimumWidthRequest="100"/>
        <Image x:Name="Image2" Source="bridge.jpeg" MinimumWidthRequest="100"
               Grid.Row="1"/>
        <Image x:Name="Image3" Source="bridge.jpeg" MinimumWidthRequest="100"
               Grid.Row="2"/>
        <Button Text="Single" Grid.Column="1" Clicked="SingleButton_Clicked"/>
        <Button Text="Compound" Grid.Row="1" Grid.Column="1" Clicked="CompoundButton_Clicked"/>
        <Button Text="Composite" Grid.Row="2" Grid.Column="1" Clicked="CompositeButton_Clicked"/>
        <Button Grid.Row="3" Grid.ColumnSpan="2" Text="Cancel" Clicked="CancelButton_Clicked"/>
    </Grid>
</ContentPage>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace BasicAnimationsSample
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        async void SingleButton_Clicked(System.Object sender, System.EventArgs e)
        {
            await Image1.RelScaleTo(2, 500);
        }

        async void CompoundButton_Clicked(System.Object sender, System.EventArgs e)
        {
            await Image2.ScaleTo(2,500);
            //await Image2.RelRotateTo(30,1000);
        }

       async void CompositeButton_Clicked(System.Object sender, System.EventArgs e)
        {
            await Task.WhenAll(
                Image3.RotateTo(360, 10000),
                Image3.FadeTo(0,10000));
        }

        void CancelButton_Clicked(System.Object sender, System.EventArgs e)
        {
            ViewExtensions.CancelAnimations(Image1);
            ViewExtensions.CancelAnimations(Image2);
            ViewExtensions.CancelAnimations(Image3);
        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值