0

I've created a launch animation in Xamarin for an iOS app but I can't seem to get the images to fade in and out gracefully. I think I need to use the .FadeTo() method but I'm unable to apply it to my code properly. I'm trying to get the first image to fade in then fade out while the second image fades in and so on. Any help is appreciated - I'm a newb!

Here's my code:

using System.Drawing;
using MonoTouch.UIKit;

namespace MapView {

public class ImageViewController : UIViewController {

    UIImageView animatedlaunchImage;

    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();
        Title = "Animated ImageView";
        View.BackgroundColor = UIColor.White;

        // an animating image
        animatedlaunchImage = new UIImageView();
        animatedlaunchImage.AnimationImages = new UIImage[] {
              UIImage.FromBundle ("Splash01.png")
            , UIImage.FromBundle ("Splash02.png")
            , UIImage.FromBundle ("Splash03.png")
            , UIImage.FromBundle ("Splash04.png")
            , UIImage.FromBundle ("Splash05.png")

        } ;
        animatedlaunchImage.AnimationRepeatCount = 1;
        animatedlaunchImage.AnimationDuration = 3;
        animatedlaunchImage.Frame = new RectangleF(0, 0, 320, 568);
        View.AddSubview(animatedlaunchImage);
        animatedlaunchImage.StartAnimating ();
    }
 } 
}
cheriana
  • 103
  • 2
  • 2
  • 14

1 Answers1

0

Include CoreAnimation and add these lines of code after you create the UIImageView,

CATransition customTransition = new CATransition();
customTransition.FadeInDuration = 1.0f;
customTransition.FadeOutDuration = 1.0f;
customTransition.TimingFunction = CAMediaTimingFunction.FromName(
    CAMediaTimingFunction.EaseInEaseOut);
customTransition.Type = CATransition.TransitionFade;

animatedlaunchImage.Layer.AddAnimation(customTransition, null);

Translated from this objective-c question.

Community
  • 1
  • 1
chriszumberge
  • 844
  • 2
  • 18
  • 33