简体   繁体   English

LaunchImage持久

[英]LaunchImage persistent

Using Xcode 7 I wanna to create a small application with a UIWebView. 使用Xcode 7,我想用UIWebView创建一个小型应用程序。 This app will have to run it from all devices. 这个应用程式必须在所有装置上执行。 I'm using "New iOS Launch Image" in Assets. 我在Assets中使用“ New iOS Launch Image”。 But when the "Launch" terminate there is a waiting time (which varies from connection speed ) before that WebView is loaded . 但是,当“启动”终止时,在加载WebView之前会有一个等待时间(随连接速度而变化)。 In this time I would like to "Launch Screen" that continue to persist using the Image for the type of device . 在这个时候,我想“启动屏幕”继续使用Image作为设备类型。

Can you help me? 你能帮助我吗?

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. 您不能按照Apple的建议增加启动屏幕的时间,但是您可以做一些会使用户感到启动屏幕仍然存在的操作。 You can achieve it in this way: 您可以通过以下方式实现:

I am assuming that the first screen load after your splash screen is your WebView screen. 我假设初始屏幕之后的第一个屏幕加载是WebView屏幕。 Add UIImageView on your WebView in interface builder and set splash screen image on your ImageView. 在界面生成器中的WebView上添加UIImageView并在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. 现在,为该imageView制作IBOutlet,并在webview提示您其代理方法中已加载该属性时将其hidden属性设置为yes。 Don't forget to set the delegate of your UIWebView in interface Builder. 不要忘记在接口Builder中设置UIWebView的委托。

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
    }

}

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. 我为正在使用的设备屏幕获取正确的图像“ LaunchImage”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM