ImageView change transition

razvanrazvan USMember

I am developing an app with Xamarin.IOS and i am not using Xamarin.Forms.
I have a screen where i have set an Image View.
Now i would like to change between 2/3/4 images with a transition (fade, move in ... does not matter).
Is there a way i can do that?
Here is my code until now:

    imgView.AnimationImages = new UIImage[] {
        UIImage.FromBundle ("tmp_running.jpg")
        , UIImage.FromBundle ("tmp_cycling.jpg")

    } ;
    imgView.AnimationRepeatCount = 0;
    imgView.AnimationDuration = 3;
    imgView.StartAnimating ();

I have tried the approach:

    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);

But nothing worked.

Do you know how to do this simple task?

Tagged:

Answers

  • razvanrazvan USMember

    Nevermind, solved it from stackoverflow.
    Here is the solution:

                public override void ViewDidLoad ()
        {
    
            base.ViewDidLoad ();
            LoadImagesAnimation ();
    
        }
    
    
        public void LoadImagesAnimation()
        {
            RectangleF screenRect = (RectangleF) UIScreen.MainScreen.Bounds;
            float screenWidth = screenRect.Width;
            float screenHeight = screenRect.Height;
            _imageView = new UIImageView (new CGRect(0, 0, screenWidth, screenHeight));
            _imageView.Image = new UIImage ("1.jpg");
            _imageView.ContentMode = UIViewContentMode.ScaleAspectFill;
            Add (_imageView);
            animateImage ();
        }
    
    
        public void animateImage()
        {
            var animationImages = new List<UIImage> () {
                UIImage.FromFile ("1.jpg"),
                UIImage.FromFile ("2.jpg")};
    
            UIImage image = animationImages[count % animationImages.Count];
    
            UIView.Transition (_imageView, 3.0,
                UIViewAnimationOptions.TransitionCrossDissolve,
                () => {_imageView.Image = image;},
                () => { animateImage ();
                    count++; }
            );
        }
    
Sign In or Register to comment.