我正在使用 Xamarin.IOS 开发应用程序,但我没有使用 Xamarin.Forms。
我有一个设置了 ImageView 的屏幕。
现在我想在带有过渡的 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);
但没有任何效果。
你知道怎么做这个简单的任务吗?
可以这样做:
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++; }
);
}
关于ios - Xamarin iOS 图像更改过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32299807/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |