MonoTouch防溅音量控制器

本文关键字:控制器 MonoTouch | 更新日期: 2023-09-27 18:28:38

我正在尝试为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我已经在应用程序的根文件夹中有图像文件,并标记为内容。它们只是在应用程序加载时持续时间不够长。

MonoTouch防溅音量控制器

更改了一些变量名,但我希望这能有所帮助。。。

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

什么是App.AppFile()

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

iOS还将为您处理@2x的内容。

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

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
}