Make a custom launch page in my IOS application with fade out image





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-2















So I am making a custom launch first page for my app. I am navigating to the next screen with a Timer. However my question is about my first page. When I launch the app I want the image that I am using to appear right away. I am not even sure if this is an option. because all apps that I see, when I launch it takes some time to load. I was wondering if this is the reason there is a delay for the image to appear or I can do something to make it appear instantly? I have attached my code below:



import UIKit

class LaunchViewController: UIViewController {

override func viewWillAppear(_ animated: Bool) {

}
override func viewDidLoad() {
super.viewDidLoad()
let gameTimer = Timer.scheduledTimer(timeInterval: 3, target: self, selector: #selector(runTimedCode), userInfo: nil, repeats: false)
}
override func viewDidAppear(_ animated: Bool) {
let imageView = UIImageView()
imageView.image = UIImage(named: "image1")
self.view.addSubview(imageView)

imageView.fadeOut()
imageView.contentMode = .scaleAspectFit
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
imageView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
imageView.topAnchor.constraint(equalTo: view.topAnchor,constant:20).isActive = true
imageView.bottomAnchor.constraint(equalTo: view.bottomAnchor,constant:30).isActive = true
imageView.trailingAnchor.constraint(equalTo: view.trailingAnchor,constant:10).isActive = true
imageView.leadingAnchor.constraint(equalTo: view.leadingAnchor,constant:10).isActive = true
}

@objc func runTimedCode()
{
self.performSegue(withIdentifier: "fromLaunch", sender: self)
}
}
extension UIView {

func fadeIn(){
UIView.animate(withDuration: 3.0, delay: 0.0, options: UIView.AnimationOptions.curveEaseIn, animations: {
self.alpha = 1.0
}, completion: nil)
}

func fadeOut(){
UIView.animate(withDuration: 2.0, delay: 1.0, options: UIView.AnimationOptions.curveEaseOut, animations: {
self.alpha = 0.0
}, completion: nil)
}

}









share|improve this question































    -2















    So I am making a custom launch first page for my app. I am navigating to the next screen with a Timer. However my question is about my first page. When I launch the app I want the image that I am using to appear right away. I am not even sure if this is an option. because all apps that I see, when I launch it takes some time to load. I was wondering if this is the reason there is a delay for the image to appear or I can do something to make it appear instantly? I have attached my code below:



    import UIKit

    class LaunchViewController: UIViewController {

    override func viewWillAppear(_ animated: Bool) {

    }
    override func viewDidLoad() {
    super.viewDidLoad()
    let gameTimer = Timer.scheduledTimer(timeInterval: 3, target: self, selector: #selector(runTimedCode), userInfo: nil, repeats: false)
    }
    override func viewDidAppear(_ animated: Bool) {
    let imageView = UIImageView()
    imageView.image = UIImage(named: "image1")
    self.view.addSubview(imageView)

    imageView.fadeOut()
    imageView.contentMode = .scaleAspectFit
    imageView.translatesAutoresizingMaskIntoConstraints = false
    imageView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
    imageView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
    imageView.topAnchor.constraint(equalTo: view.topAnchor,constant:20).isActive = true
    imageView.bottomAnchor.constraint(equalTo: view.bottomAnchor,constant:30).isActive = true
    imageView.trailingAnchor.constraint(equalTo: view.trailingAnchor,constant:10).isActive = true
    imageView.leadingAnchor.constraint(equalTo: view.leadingAnchor,constant:10).isActive = true
    }

    @objc func runTimedCode()
    {
    self.performSegue(withIdentifier: "fromLaunch", sender: self)
    }
    }
    extension UIView {

    func fadeIn(){
    UIView.animate(withDuration: 3.0, delay: 0.0, options: UIView.AnimationOptions.curveEaseIn, animations: {
    self.alpha = 1.0
    }, completion: nil)
    }

    func fadeOut(){
    UIView.animate(withDuration: 2.0, delay: 1.0, options: UIView.AnimationOptions.curveEaseOut, animations: {
    self.alpha = 0.0
    }, completion: nil)
    }

    }









    share|improve this question



























      -2












      -2








      -2








      So I am making a custom launch first page for my app. I am navigating to the next screen with a Timer. However my question is about my first page. When I launch the app I want the image that I am using to appear right away. I am not even sure if this is an option. because all apps that I see, when I launch it takes some time to load. I was wondering if this is the reason there is a delay for the image to appear or I can do something to make it appear instantly? I have attached my code below:



      import UIKit

      class LaunchViewController: UIViewController {

      override func viewWillAppear(_ animated: Bool) {

      }
      override func viewDidLoad() {
      super.viewDidLoad()
      let gameTimer = Timer.scheduledTimer(timeInterval: 3, target: self, selector: #selector(runTimedCode), userInfo: nil, repeats: false)
      }
      override func viewDidAppear(_ animated: Bool) {
      let imageView = UIImageView()
      imageView.image = UIImage(named: "image1")
      self.view.addSubview(imageView)

      imageView.fadeOut()
      imageView.contentMode = .scaleAspectFit
      imageView.translatesAutoresizingMaskIntoConstraints = false
      imageView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
      imageView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
      imageView.topAnchor.constraint(equalTo: view.topAnchor,constant:20).isActive = true
      imageView.bottomAnchor.constraint(equalTo: view.bottomAnchor,constant:30).isActive = true
      imageView.trailingAnchor.constraint(equalTo: view.trailingAnchor,constant:10).isActive = true
      imageView.leadingAnchor.constraint(equalTo: view.leadingAnchor,constant:10).isActive = true
      }

      @objc func runTimedCode()
      {
      self.performSegue(withIdentifier: "fromLaunch", sender: self)
      }
      }
      extension UIView {

      func fadeIn(){
      UIView.animate(withDuration: 3.0, delay: 0.0, options: UIView.AnimationOptions.curveEaseIn, animations: {
      self.alpha = 1.0
      }, completion: nil)
      }

      func fadeOut(){
      UIView.animate(withDuration: 2.0, delay: 1.0, options: UIView.AnimationOptions.curveEaseOut, animations: {
      self.alpha = 0.0
      }, completion: nil)
      }

      }









      share|improve this question
















      So I am making a custom launch first page for my app. I am navigating to the next screen with a Timer. However my question is about my first page. When I launch the app I want the image that I am using to appear right away. I am not even sure if this is an option. because all apps that I see, when I launch it takes some time to load. I was wondering if this is the reason there is a delay for the image to appear or I can do something to make it appear instantly? I have attached my code below:



      import UIKit

      class LaunchViewController: UIViewController {

      override func viewWillAppear(_ animated: Bool) {

      }
      override func viewDidLoad() {
      super.viewDidLoad()
      let gameTimer = Timer.scheduledTimer(timeInterval: 3, target: self, selector: #selector(runTimedCode), userInfo: nil, repeats: false)
      }
      override func viewDidAppear(_ animated: Bool) {
      let imageView = UIImageView()
      imageView.image = UIImage(named: "image1")
      self.view.addSubview(imageView)

      imageView.fadeOut()
      imageView.contentMode = .scaleAspectFit
      imageView.translatesAutoresizingMaskIntoConstraints = false
      imageView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
      imageView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
      imageView.topAnchor.constraint(equalTo: view.topAnchor,constant:20).isActive = true
      imageView.bottomAnchor.constraint(equalTo: view.bottomAnchor,constant:30).isActive = true
      imageView.trailingAnchor.constraint(equalTo: view.trailingAnchor,constant:10).isActive = true
      imageView.leadingAnchor.constraint(equalTo: view.leadingAnchor,constant:10).isActive = true
      }

      @objc func runTimedCode()
      {
      self.performSegue(withIdentifier: "fromLaunch", sender: self)
      }
      }
      extension UIView {

      func fadeIn(){
      UIView.animate(withDuration: 3.0, delay: 0.0, options: UIView.AnimationOptions.curveEaseIn, animations: {
      self.alpha = 1.0
      }, completion: nil)
      }

      func fadeOut(){
      UIView.animate(withDuration: 2.0, delay: 1.0, options: UIView.AnimationOptions.curveEaseOut, animations: {
      self.alpha = 0.0
      }, completion: nil)
      }

      }






      swift animation fade






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 13:24









      Dharmesh

      52.6k23130151




      52.6k23130151










      asked Jan 3 at 13:22









      SaraSara

      54




      54
























          2 Answers
          2






          active

          oldest

          votes


















          0














          It would be better to move your code to viewDidLoad.
          viewDidLoad is called only once during UIViewController lifecycle.
          While viewDidAppear might be called several times.



          Since you are using Autolayout you don't need to care about correct subviews size and moving your code to viewDidLoad should be sufficient and it should resolve issue with delay you have asked about.






          share|improve this answer
























          • Ok I will try your method later today and let you know. I remember i did try the didload and did not work the way I wanted though. I ll give it another shot

            – Sara
            Jan 3 at 14:28











          • you need to add imageView in viewDidLoad. However you need to start timer on viewDidAppear. I think starting timer and adding imageView in different methods of UIViewController is a reason of inconsistent behavior. You are starting timer before adding imageView now.

            – Eugene El
            Jan 3 at 14:59













          • I tried your suggestion too. did not work :(

            – Sara
            Jan 4 at 0:06



















          0














          You could try moving your code from viewDidAppear to viewWillLayoutSubviews.



          Note however that there is always a delay between the user tapping on your app's icon and the appearance of your first screen. That is why you have a LaunchScreen.storyboard - it is what is shown during that delay. So maybe you should put your image in the LaunchScreen.storyboard. Note that you cannot run any code in conjunction with the LaunchScreen.storyboard.






          share|improve this answer


























          • Ok i had to leave my computer. I will check back in few hours and let you know. Thanks for the quick response

            – Sara
            Jan 3 at 13:39













          • so I moved the code to what you suggested and I still see a blank page when the app loads before my image shows up :(

            – Sara
            Jan 4 at 0:02











          • Then you're not sharing enough information. Try to reproduce this problem starting from a totally blank Single View App project template and, if you can do so, describe to us how to see the problem you're seeing.

            – matt
            Jan 4 at 0:33












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54023161%2fmake-a-custom-launch-page-in-my-ios-application-with-fade-out-image%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          It would be better to move your code to viewDidLoad.
          viewDidLoad is called only once during UIViewController lifecycle.
          While viewDidAppear might be called several times.



          Since you are using Autolayout you don't need to care about correct subviews size and moving your code to viewDidLoad should be sufficient and it should resolve issue with delay you have asked about.






          share|improve this answer
























          • Ok I will try your method later today and let you know. I remember i did try the didload and did not work the way I wanted though. I ll give it another shot

            – Sara
            Jan 3 at 14:28











          • you need to add imageView in viewDidLoad. However you need to start timer on viewDidAppear. I think starting timer and adding imageView in different methods of UIViewController is a reason of inconsistent behavior. You are starting timer before adding imageView now.

            – Eugene El
            Jan 3 at 14:59













          • I tried your suggestion too. did not work :(

            – Sara
            Jan 4 at 0:06
















          0














          It would be better to move your code to viewDidLoad.
          viewDidLoad is called only once during UIViewController lifecycle.
          While viewDidAppear might be called several times.



          Since you are using Autolayout you don't need to care about correct subviews size and moving your code to viewDidLoad should be sufficient and it should resolve issue with delay you have asked about.






          share|improve this answer
























          • Ok I will try your method later today and let you know. I remember i did try the didload and did not work the way I wanted though. I ll give it another shot

            – Sara
            Jan 3 at 14:28











          • you need to add imageView in viewDidLoad. However you need to start timer on viewDidAppear. I think starting timer and adding imageView in different methods of UIViewController is a reason of inconsistent behavior. You are starting timer before adding imageView now.

            – Eugene El
            Jan 3 at 14:59













          • I tried your suggestion too. did not work :(

            – Sara
            Jan 4 at 0:06














          0












          0








          0







          It would be better to move your code to viewDidLoad.
          viewDidLoad is called only once during UIViewController lifecycle.
          While viewDidAppear might be called several times.



          Since you are using Autolayout you don't need to care about correct subviews size and moving your code to viewDidLoad should be sufficient and it should resolve issue with delay you have asked about.






          share|improve this answer













          It would be better to move your code to viewDidLoad.
          viewDidLoad is called only once during UIViewController lifecycle.
          While viewDidAppear might be called several times.



          Since you are using Autolayout you don't need to care about correct subviews size and moving your code to viewDidLoad should be sufficient and it should resolve issue with delay you have asked about.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 3 at 13:56









          Eugene ElEugene El

          613




          613













          • Ok I will try your method later today and let you know. I remember i did try the didload and did not work the way I wanted though. I ll give it another shot

            – Sara
            Jan 3 at 14:28











          • you need to add imageView in viewDidLoad. However you need to start timer on viewDidAppear. I think starting timer and adding imageView in different methods of UIViewController is a reason of inconsistent behavior. You are starting timer before adding imageView now.

            – Eugene El
            Jan 3 at 14:59













          • I tried your suggestion too. did not work :(

            – Sara
            Jan 4 at 0:06



















          • Ok I will try your method later today and let you know. I remember i did try the didload and did not work the way I wanted though. I ll give it another shot

            – Sara
            Jan 3 at 14:28











          • you need to add imageView in viewDidLoad. However you need to start timer on viewDidAppear. I think starting timer and adding imageView in different methods of UIViewController is a reason of inconsistent behavior. You are starting timer before adding imageView now.

            – Eugene El
            Jan 3 at 14:59













          • I tried your suggestion too. did not work :(

            – Sara
            Jan 4 at 0:06

















          Ok I will try your method later today and let you know. I remember i did try the didload and did not work the way I wanted though. I ll give it another shot

          – Sara
          Jan 3 at 14:28





          Ok I will try your method later today and let you know. I remember i did try the didload and did not work the way I wanted though. I ll give it another shot

          – Sara
          Jan 3 at 14:28













          you need to add imageView in viewDidLoad. However you need to start timer on viewDidAppear. I think starting timer and adding imageView in different methods of UIViewController is a reason of inconsistent behavior. You are starting timer before adding imageView now.

          – Eugene El
          Jan 3 at 14:59







          you need to add imageView in viewDidLoad. However you need to start timer on viewDidAppear. I think starting timer and adding imageView in different methods of UIViewController is a reason of inconsistent behavior. You are starting timer before adding imageView now.

          – Eugene El
          Jan 3 at 14:59















          I tried your suggestion too. did not work :(

          – Sara
          Jan 4 at 0:06





          I tried your suggestion too. did not work :(

          – Sara
          Jan 4 at 0:06













          0














          You could try moving your code from viewDidAppear to viewWillLayoutSubviews.



          Note however that there is always a delay between the user tapping on your app's icon and the appearance of your first screen. That is why you have a LaunchScreen.storyboard - it is what is shown during that delay. So maybe you should put your image in the LaunchScreen.storyboard. Note that you cannot run any code in conjunction with the LaunchScreen.storyboard.






          share|improve this answer


























          • Ok i had to leave my computer. I will check back in few hours and let you know. Thanks for the quick response

            – Sara
            Jan 3 at 13:39













          • so I moved the code to what you suggested and I still see a blank page when the app loads before my image shows up :(

            – Sara
            Jan 4 at 0:02











          • Then you're not sharing enough information. Try to reproduce this problem starting from a totally blank Single View App project template and, if you can do so, describe to us how to see the problem you're seeing.

            – matt
            Jan 4 at 0:33
















          0














          You could try moving your code from viewDidAppear to viewWillLayoutSubviews.



          Note however that there is always a delay between the user tapping on your app's icon and the appearance of your first screen. That is why you have a LaunchScreen.storyboard - it is what is shown during that delay. So maybe you should put your image in the LaunchScreen.storyboard. Note that you cannot run any code in conjunction with the LaunchScreen.storyboard.






          share|improve this answer


























          • Ok i had to leave my computer. I will check back in few hours and let you know. Thanks for the quick response

            – Sara
            Jan 3 at 13:39













          • so I moved the code to what you suggested and I still see a blank page when the app loads before my image shows up :(

            – Sara
            Jan 4 at 0:02











          • Then you're not sharing enough information. Try to reproduce this problem starting from a totally blank Single View App project template and, if you can do so, describe to us how to see the problem you're seeing.

            – matt
            Jan 4 at 0:33














          0












          0








          0







          You could try moving your code from viewDidAppear to viewWillLayoutSubviews.



          Note however that there is always a delay between the user tapping on your app's icon and the appearance of your first screen. That is why you have a LaunchScreen.storyboard - it is what is shown during that delay. So maybe you should put your image in the LaunchScreen.storyboard. Note that you cannot run any code in conjunction with the LaunchScreen.storyboard.






          share|improve this answer















          You could try moving your code from viewDidAppear to viewWillLayoutSubviews.



          Note however that there is always a delay between the user tapping on your app's icon and the appearance of your first screen. That is why you have a LaunchScreen.storyboard - it is what is shown during that delay. So maybe you should put your image in the LaunchScreen.storyboard. Note that you cannot run any code in conjunction with the LaunchScreen.storyboard.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 4 at 0:36

























          answered Jan 3 at 13:28









          mattmatt

          335k47551748




          335k47551748













          • Ok i had to leave my computer. I will check back in few hours and let you know. Thanks for the quick response

            – Sara
            Jan 3 at 13:39













          • so I moved the code to what you suggested and I still see a blank page when the app loads before my image shows up :(

            – Sara
            Jan 4 at 0:02











          • Then you're not sharing enough information. Try to reproduce this problem starting from a totally blank Single View App project template and, if you can do so, describe to us how to see the problem you're seeing.

            – matt
            Jan 4 at 0:33



















          • Ok i had to leave my computer. I will check back in few hours and let you know. Thanks for the quick response

            – Sara
            Jan 3 at 13:39













          • so I moved the code to what you suggested and I still see a blank page when the app loads before my image shows up :(

            – Sara
            Jan 4 at 0:02











          • Then you're not sharing enough information. Try to reproduce this problem starting from a totally blank Single View App project template and, if you can do so, describe to us how to see the problem you're seeing.

            – matt
            Jan 4 at 0:33

















          Ok i had to leave my computer. I will check back in few hours and let you know. Thanks for the quick response

          – Sara
          Jan 3 at 13:39







          Ok i had to leave my computer. I will check back in few hours and let you know. Thanks for the quick response

          – Sara
          Jan 3 at 13:39















          so I moved the code to what you suggested and I still see a blank page when the app loads before my image shows up :(

          – Sara
          Jan 4 at 0:02





          so I moved the code to what you suggested and I still see a blank page when the app loads before my image shows up :(

          – Sara
          Jan 4 at 0:02













          Then you're not sharing enough information. Try to reproduce this problem starting from a totally blank Single View App project template and, if you can do so, describe to us how to see the problem you're seeing.

          – matt
          Jan 4 at 0:33





          Then you're not sharing enough information. Try to reproduce this problem starting from a totally blank Single View App project template and, if you can do so, describe to us how to see the problem you're seeing.

          – matt
          Jan 4 at 0:33


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54023161%2fmake-a-custom-launch-page-in-my-ios-application-with-fade-out-image%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

          How to fix TextFormField cause rebuild widget in Flutter