MonoTouch飞溅推子

时间:2012-03-20 19:37:15

标签: c# xamarin.ios splash-screen

我正在尝试为MonoTouch创建一个启动画面,它会在很短的时间内从Default.png淡化到应用程序。

这是我到目前为止在AppDelegate中所拥有的,

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
    window = new UIWindow (UIScreen.MainScreen.Bounds);
    viewController = new App1ViewController ();
    navController = new UINavigationController(viewController);

    UIImageView splash = new UIImageView(window.Bounds);
    splash.Image = UIImage.FromFile("Default.png");
    splash.Alpha = 1.0f;

    window.AddSubview(splash);
    UIView.Animate(5,
    delegate
    {
        splash.Alpha = 0.0f;
    },
    delegate
    {
        Console.WriteLine("Removed.");
        splash.RemoveFromSuperview();
        window.RootViewController = navController;
    });
    window.MakeKeyAndVisible();

    return true;
}

但到目前为止它不起作用/显示任何东西。此外,是否有一个事件来完成动画,所以我可以删除视图?这是解决这个问题的正确方法吗?

PS我已将应用程序的根文件夹中的图像文件标记为内容。它们在应用程序负载上的持续时间不够长。

3 个答案:

答案 0 :(得分:2)

更改了一些变量名称,但我希望这会有所帮助...

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        window = new UIWindow (UIScreen.MainScreen.Bounds);

        UIImageView splash = new UIImageView(window.Bounds);
        splash.Image = UIImage.FromFile("Default.png");

        var vc = new UIViewController ();
        var nav = new UINavigationController(vc);

        window.AddSubview(splash);
        window.AddSubview(nav.View);
        window.BringSubviewToFront(splash);
        window.MakeKeyAndVisible();

        UIView.Animate(5,
        delegate
        {
            splash.Alpha = 0f;
        },
        delegate
        {
            Console.WriteLine("Removed.");
        window.RootViewController = nav;
            splash.RemoveFromSuperview();

        });

        return true;
    }

答案 1 :(得分:0)

什么是App.AppFile()

如果它位于您应用的根目录中,您应该能够使用UIImage.FromFile("Default.png")

iOS也会为你处理@ 2x的东西。

答案 2 :(得分:0)

从FinishedLaunching希望调用此函数,以便通过此代码解决您的问题

public void LaunchSpinner()
{
// launch  spinner for 2 secs
ActivityIndicator objLoadView = new ActivityIndicator ("Please Wait......");
NSTimer.CreateScheduledTimer (TimeSpan.FromSeconds (2), () => objLoadView.StopAnimatings ());
}

public class ActivityIndicator : UIActivityIndicatorView
{
UIAlertView _alert;
UIActivityIndicatorView _ai =new UIActivityIndicatorView(); 
public ActivityIndicator()
 {

 }
public ActivityIndicator (String title)
{
_alert = new UIAlertView (title, String.Empty, null, null, null);
_ai = new UIActivityIndicatorView ();
_ai.Frame = new System.Drawing.RectangleF (125, 50, 40, 40);
_ai.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge;
_alert.AddSubview (_ai);
_ai.StartAnimating ();
_alert.Show (); 
}

public void StopAnimatings ()
{           
_ai.StopAnimating ();
_alert.DismissWithClickedButtonIndex (0, true);
_alert.Hidden = true;
_ai.HidesWhenStopped = true;                    
}
#region IDisposable implementation
void IDisposable.Dispose ()
{
 _alert.DismissWithClickedButtonIndex(0, true);
}
#endregion
}