locked
how to load application main page after custom lunch screen viewcontroller RRS feed

  • Question

  • User381770 posted

    Hi All, how to load application main page after custom lunch screen viewcontroller

    public override bool FinishedLaunching(UIApplication app, NSDictionary options) { global::Xamarin.Forms.Forms.Init();

            Window = new UIWindow(UIScreen.MainScreen.Bounds);
    
            var controller = new ViewController();
            controller.View.BackgroundColor = UIColor.White;
    
            Window.RootViewController = controller;
    
            // make the window visible
            Window.MakeKeyAndVisible();
          System.Threading.Thread.Sleep(15000);*///will wait for 4 seconds
           LoadApplication(new App());
            return base.FinishedLaunching(app, options);
    
        }
    

    if i do like this immediately launching application without visibiling my custom launch screen uicontroller even if i put thread.sleep also it is loading application without displaying launchscreen controller .suppose if remove LoadApplication(new App()); then my launchcontroller is displaying.suppose if i remove LoadApplication(new App()); then where i need to call this(i need to navigate to application after launch screen).

      please post here if any one knows about this
    
    Tuesday, February 12, 2019 10:31 AM

Answers

  • User369979 posted

    @Sumit_Sharma Please notice that launch screen storyboard can't add any code behind including animation code. @divyagarimella Change your AppDelegate like:

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        global::Xamarin.Forms.Forms.Init();
    
        Window = new UIWindow(UIScreen.MainScreen.Bounds);
    
        var controller = new ViewController();
        controller.View.BackgroundColor = UIColor.White;
        Window.RootViewController = controller;
        // make the window visible
        Window.MakeKeyAndVisible();
    
        MessagingCenter.Subscribe<object, object>(this, "ShowMainScreen", (sender, args) =>
        {
            LoadApplication(new App());
            base.FinishedLaunching(app, options);
        });
    
        return true;
    }
    

    Then in your ViewController class, when the animation has finished and you want to show your main screen in Forms trigger the MessagingCenter like: MessagingCenter.Send<object, object>(this, "ShowMainScreen", null);

    Another workaround is adding this custom launching page on Forms project:

    if (Device.RuntimePlatform == Device.iOS)
    {
        MainPage = new LaunchPage();
    }
    else
    {
        MainPage = new MainPage();
    }
    

    And create a custom renderer for this LaunchPage, place your animation there.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, February 13, 2019 5:33 AM

All replies

  • User324047 posted

    You can create your own LaunchScreen in XF.iOS project then you need to set it on your info.plist like this

    Tuesday, February 12, 2019 11:42 AM
  • User381770 posted

    i am creating custom launchscreen (with animation) that's why i created custom uicontroller for launch screen.if it is normal launchscreen then we can do like above screenshot

    Tuesday, February 12, 2019 11:58 AM
  • User324047 posted

    That's what I am saying

    Create a StoryBoard and set it like this

    Tuesday, February 12, 2019 12:48 PM
  • User381770 posted

    if we do like this do we need to call it externally like Window = new UIWindow(UIScreen.MainScreen.Bounds);

        var controller = new ViewController();
        controller.View.BackgroundColor = UIColor.White;
    
        Window.RootViewController = controller;
    
        // make the window visible
        Window.MakeKeyAndVisible();
    
    Tuesday, February 12, 2019 1:49 PM
  • User324047 posted

    I don't think so, because when you set the launch screen it will be called first before your LoadApplication in Appdelegate will be called. In your storyboard you can add a cs file as well, and try animating, delaying thread there.

    Wednesday, February 13, 2019 2:47 AM
  • User369979 posted

    @Sumit_Sharma Please notice that launch screen storyboard can't add any code behind including animation code. @divyagarimella Change your AppDelegate like:

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        global::Xamarin.Forms.Forms.Init();
    
        Window = new UIWindow(UIScreen.MainScreen.Bounds);
    
        var controller = new ViewController();
        controller.View.BackgroundColor = UIColor.White;
        Window.RootViewController = controller;
        // make the window visible
        Window.MakeKeyAndVisible();
    
        MessagingCenter.Subscribe<object, object>(this, "ShowMainScreen", (sender, args) =>
        {
            LoadApplication(new App());
            base.FinishedLaunching(app, options);
        });
    
        return true;
    }
    

    Then in your ViewController class, when the animation has finished and you want to show your main screen in Forms trigger the MessagingCenter like: MessagingCenter.Send<object, object>(this, "ShowMainScreen", null);

    Another workaround is adding this custom launching page on Forms project:

    if (Device.RuntimePlatform == Device.iOS)
    {
        MainPage = new LaunchPage();
    }
    else
    {
        MainPage = new MainPage();
    }
    

    And create a custom renderer for this LaunchPage, place your animation there.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, February 13, 2019 5:33 AM
  • User381770 posted

    Thank you so much @LandLu Its very helpful and one more thing my gif image is not animating here its only showing static image instead of gif.if you have any idea please tell me logoGifImageView = new UIImageView(UIImage.FromBundle("launchscreen.gif")); animation.logoGifImageView.AnimationDuration = 1; animation.logoGifImageView.AnimationRepeatCount = 0;

            animation.logoGifImageView.StartAnimating();
    
    Wednesday, February 13, 2019 9:41 AM
  • User381770 posted

    and i tried like this also but it's also showing all static images instead of gif images var array = new UIImage[] { UIImage.FromBundle ("home.gif") , UIImage.FromBundle ("outofhour.gif") , UIImage.FromBundle ("quotes.gif") , UIImage.FromBundle ("schedule.gif") }; animation.logoGifImageView.AnimationImages = array; animation.logoGifImageView.AnimationDuration = 1; animation.logoGifImageView.AnimationRepeatCount = 0; animation.logoGifImageView.StartAnimating();

    Wednesday, February 13, 2019 9:42 AM
  • User369979 posted

    Please share your sample if possible, as it could be your gif files' issue. Without them, I can't reproduce your issues on my side.

    Wednesday, February 13, 2019 9:44 AM
  • User381770 posted

    sorry i forgot to tell you my gif image is in Resources folder of xamarin ios project.i think its taking path that's why its showing static image

    Wednesday, February 13, 2019 9:45 AM
  • User369979 posted

    Moreover, UIImageView can play a set of static images so that it looks like a gif file. You can try this to play a gif file directly: https://github.com/xamarin/ios-samples/blob/master/ios11/SamplePhotoApp/Shared/AnimatedImageView.cs

    Wednesday, February 13, 2019 10:07 AM
  • User381770 posted

    hi @LandLu Please find my attached sample project

    Wednesday, February 13, 2019 10:38 AM
  • User151685 posted

    @divyagarimella have you find the solution ? I am stuck here as well

    Wednesday, May 8, 2019 6:35 AM
  • User151685 posted

    Hey Thanks @LandLu I got the idea from your answer, solved my issue, In my case I don't need this

    MessagingCenter.Subscribe(this, "ShowMainScreen", (sender, args) => { LoadApplication(new App()); base.FinishedLaunching(app, options); });

    exactly but I got the event where I can call LoadApplication.

    Thanks @divyagarimella to you as well.

    Thursday, May 9, 2019 8:55 AM