我正在使用Xamarin.IOS开发一个应用程序,我没有使用Xamarin.Forms 我有一个屏幕,我已经设置了一个图像视图 现在我想在2/3/4图像之间进行转换(淡入淡出,移入...无所谓) 有没有办法可以做到这一点? 这是我的代码,直到现在:
imgView.AnimationImages = new UIImage[] {
UIImage.FromBundle ("tmp_running.jpg")
, UIImage.FromBundle ("tmp_cycling.jpg")
} ;
imgView.AnimationRepeatCount = 0;
imgView.AnimationDuration = 3;
imgView.StartAnimating ();
我尝试过这种方法:
CATransition customTransition = new CATransition();
customTransition.FadeInDuration = 3.0f;
customTransition.FadeOutDuration = 3.0f;
customTransition.TimingFunction = CAMediaTimingFunction.FromName(
CAMediaTimingFunction.EaseInEaseOut);
customTransition.Type = CATransition.TransitionFade;
and then :
imgView.Layer.AddAnimation(customTransition, null);
但没有任何效果。
你知道怎么做这个简单的任务吗?
答案 0 :(得分:4)
可以这样做:
static int count = 0;
UIImageView _imageView;
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
_imageView = new UIImageView (new CGRect(0, 0, 100, 100));
_imageView.Image = new UIImage ("1.png");
Add (_imageView);
animateImage ();
}
public void animateImage()
{
var animationImages = new List<UIImage> () {
UIImage.FromFile ("1.png"),
UIImage.FromFile ("2.png"),
UIImage.FromFile ("3.png"),
UIImage.FromFile ("4.png"),
UIImage.FromFile ("5.png")};
UIImage image = animationImages[count % animationImages.Count];
UIView.Transition (_imageView, 3.0,
UIViewAnimationOptions.TransitionCrossDissolve,
() => {_imageView.Image = image;},
() => { animateImage ();
count++; }
);
}