1. 程式人生 > >iOS解決App啟動時閃屏問題(swift)

iOS解決App啟動時閃屏問題(swift)

建立一個工具類MTAppHelper

import UIKit

fileprivate let isIphone4 = Int(kScreenH) == 480
fileprivate let isIphone5 = Int(kScreenH) == 568
fileprivate let isIphone6 = Int(kScreenH) == 667
fileprivate let isIphonePlus = Int(kScreenH) == 736

/// 工具類
class MTAppHelper {

/// 根據機型獲取指定機型的圖片
///
/// - returns: 指定手機型別的圖片
static func fetchLaunchImage() -> UIImage? {
    var imageName: String!
    if isIphonePlus {
        imageName = "Default-736h"
    } else if isIphone6 {
        imageName = "Default-667h"
    } else if isIphone5 {
        imageName = "
[email protected]
~iphone" } else { imageName = "[email protected]~iphone" } return UIImage(named: imageName) } }

載入UI時呼叫方法

showSplashScreenImage();

   /// 閃屏圖片檢視
lazy var splashImageView: UIImageView = UIImageView(frame: kScreenBounds)


  /// 展示閃屏圖片
private func showSplashScreenImage() {
//使用工具類方法        
 splashImageView.image = ZSAppHelper.fetchLaunchImage()
    UIApplication.shared.keyWindow?.addSubview(splashImageView)
}