0

Using Xcode 7 I wanna to create a small application with a UIWebView. This app will have to run it from all devices. I'm using "New iOS Launch Image" in Assets. But when the "Launch" terminate there is a waiting time (which varies from connection speed ) before that WebView is loaded . In this time I would like to "Launch Screen" that continue to persist using the Image for the type of device .

Can you help me?

Phocs
  • 2,430
  • 5
  • 18
  • 35

2 Answers2

0

You cannot increase the time of splash screen as recommended by apple but you can do something which will make the user feel like splash screen is still there. You can achieve it in this way:

I am assuming that the first screen load after your splash screen is your WebView screen. Add UIImageView on your WebView in interface builder and set splash screen image on your ImageView. Now make IBOutlet for this imageView and set it hidden property as yes when webview intimates you that its loaded in its delegate methods. Don't forget to set the delegate of your UIWebView in interface Builder.

class WebViewController: UIViewController, UIWebViewDelegate {
    @IBOutlet var UIImageView: imgThumbSplash!


    override func viewDidLoad() {
        super.viewDidLoad()
        imgThumbSplash.hidden = false
    }

    func webViewDidFinishLoad(webView: UIWebView){
        imgThumbSplash.hidden = true
    }


    func webView(webView: UIWebView, didFailLoadWithError error: NSError?){
         imgThumbSplash.hidden = true
    }

}
Shehzad Ali
  • 1,846
  • 10
  • 16
  • How do I set splash screen image in my ImageView? – Phocs Apr 15 '16 at 19:27
  • What do I have to connect to "IBOutlet UIImageView"? – Phocs Apr 15 '16 at 19:29
  • Here github.com/Volpesio/Launch.git (Launch.zip) is my idea of implementation to ensure that the LaunchImage remains visible after the Launch Screen. But on some iPhone the picture is distorted! because? Where did I go wrong? – Phocs Apr 17 '16 at 12:02
  • Just by setting image name in interface builder. IBOutlet is required so that you can hide it in the code when your web view is loaded – Shehzad Ali Apr 18 '16 at 10:54
  • I tried but the image is distorted, it doesn't fit to device as the Launch – Phocs Apr 18 '16 at 11:08
  • Set the image mode "scale to fill" in attribute inspector in Interface Builder after clicking on the UIImageView. Make sure aspect ratio of image and uiimageview should be same. – Shehzad Ali Apr 18 '16 at 13:48
0

I solved it with this code:

extension UIImage {
    convenience init?(fullscreenNamed name: String)  {
        switch UIScreen.mainScreen().bounds.size.height {
        case 480: //iPhone 4/4s
            self.init(named: "\(name)-700@2x.png")
        case 568: //iPhone 5/5s
            self.init(named: "\(name)-700-568h@2x.png")
        case 667: //iPhone 6/6s
            self.init(named: "\(name)-800-667h@2x.png")
        case 736: //iPhone 6+/6s+
            self.init(named: "\(name)-800-Portrait-736h@3x.png")
        default:
            self.init(named: name)
        }
    }
}

I take in "LaunchImage" the right image for the device screen in use.

Phocs
  • 2,430
  • 5
  • 18
  • 35