storyboard.instantiateViewController выполняется около 3 секунд

#ios #swift #uinavigationcontroller #storyboard

#iOS #swift #uinavigationcontroller #раскадровка

Вопрос:

Я заметил, что у моего приложения есть задержка перед представлением UIViewController , поэтому я print() выяснял, какая строка кода вызывает ее, и обнаружил, что let navigationVC = storyboard!.instantiateViewController(withIdentifier: "filterNavigationVC") as! UINavigationController она выполняется около 2 секунд. Почему это может быть так? Я пытался удалить все, кроме этого, даже без навигации, и все равно это заняло так много времени.

 @IBAction func filter(_ sender: AnyObject) {
    let navigationVC = storyboard!.instantiateViewController(withIdentifier: "filterNavigationVC") as! UINavigationController
    let destinationVC = navigationVC.topViewController as! FilterViewController
    navigationVC.modalPresentationStyle = .overCurrentContext
    destinationVC.backgroundColorValue = self.view.backgroundColor!
    destinationVC.color = themeColor.light
    destinationVC.delegate = self
    destinationVC.billModel = self.price
    destinationVC.applyedFilter = self.applyedFilter
    self.present(navigationVC, animated: true, completion: nil)
}
  

Далее UIViewController's viewDidLoad()

 override func viewDidLoad() {
    super.viewDidLoad()
    customization()
}

fileprivate func customization(){
    setupBillButtons(billModel.range["low"]!, medium: self.billModel.range["medium"]!, high: self.billModel.range["high"]!)
    tempConfigButtons([self.lowBillButton, self.mediumBillButton, self.highBillButton])
    if color == themeColor.light {
        customizeLightTheme()
    } else if color == themeColor.dark {
        customizeDarkTheme()
    }
    setCharacterSpacingForLabels([typeLabel, kitchenLabel, avarageBill, metroLabel, tagsLabel], spacing: 2.79)
    setSeparatorInsets([kitchenTableView, metroTableView, typeTableView], edge: UIEdgeInsetsMake(0, 20, 0, 20))
    backgroundVoew.backgroundColor = backgroundColorValue
    backgroundVoew.addBackroundBlur()
    self.navigationController?.navigationBar.isHidden = true
}

fileprivate func customizeDarkTheme() {
    comfirmButton.setImage(UIImage(named: "comfirmLight"), for: UIControlState())
    dismissButton.setImage(UIImage(named: "closeLight"), for: UIControlState())
    setColorsForTableViews([kitchenTableView, metroTableView, typeTableView], separatorColor: colorWithAlpha(whiteColor, alpha: 0.05), tintColor: colorWithAlpha(whiteColor, alpha: 0.5))
    setColorForLabels([kitchenLabel, avarageBill, metroLabel, typeLabel, tagsLabel], color: colorWithAlpha(whiteColor, alpha: 0.50))
    topName.textColor = whiteColor  

    UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent

    self.view.backgroundColor = backgroundColorValue

    bottomComfitmButton.tintColor = whiteColor
    bottomComfitmButton.backgroundColor = colorWithAlpha(whiteColor, alpha: 0.15)
    showAllTags.titleLabel!.addCharactersSpacing(-0.39, text: (self.showAllTags.titleLabel?.text)!)
    showAllTags.setTitleColor(colorWithAlpha(whiteColor, alpha: 0.5), for: UIControlState())
    showAllFilterImage.image = UIImage(named: "filterShowAllDark")
}

fileprivate func customizeLightTheme() {
    comfirmButton.setImage(UIImage(named: "comfirmDark"), for: UIControlState())
    dismissButton.setImage(UIImage(named: "closeDark"), for: UIControlState())
    setColorForLabels([kitchenLabel, avarageBill, metroLabel, typeLabel, tagsLabel], color: colorWithAlpha(grayColor, alpha: 0.50))
    topName.textColor = grayColor 
    setColorsForTableViews([kitchenTableView, metroTableView, typeTableView], separatorColor: colorWithAlpha(grayColor, alpha: 0.1), tintColor: colorWithAlpha(grayColor, alpha: 0.59))
    UIApplication.shared.statusBarStyle = UIStatusBarStyle.default
    bottomComfitmButton.tintColor = grayColor
    bottomComfitmButton.backgroundColor = colorWithAlpha(whiteColor, alpha: 0.25) 
    showAllTags.titleLabel!.addCharactersSpacing(-0.39, text: (self.showAllTags.titleLabel?.text)!)
    showAllTags.setTitleColor(colorWithAlpha(grayColor, alpha: 0.5), for: UIControlState())
    showAllFilterImage.image = UIImage(named: "filterShowAllLight")
}

fileprivate func setupBillButtons(_ low: Bool, medium: Bool, high: Bool) {
    lowBillButton.isSelected = low
    mediumBillButton.isSelected = medium
    highBillButton.isSelected = high
}

fileprivate func setSeparatorInsets(_ tableViews: [UITableView], edge: UIEdgeInsets) {
    for tableView in tableViews {
        tableView.separatorInset = edge
    }
}

fileprivate func tempConfigButtons(_ buttons: [UIButton]) {
    for button in buttons {
        button.setTitleColor(whiteColor, for: .selected)
        if self.color == themeColor.dark {
            button.setBackgroundColor(colorWithAlpha(whiteColor, alpha: 0.50), forState: .selected)
            button.setTitleColor(whiteColor, for: UIControlState())
            DispatchQueue.main.async(execute: {
                button.roundCorners([.topLeft, .topRight, .bottomLeft, .bottomRight], radius: 15, borderColor: self.colorWithAlpha(self.whiteColor, alpha: 0.50), borderWidth: 1)
            })
        } else {
            button.setTitleColor(grayColor, for: UIControlState())
            button.setBackgroundColor(colorWithAlpha(grayColor, alpha: 0.50), forState: .selected)
            DispatchQueue.main.async(execute: {
                button.roundCorners([.topLeft, .topRight, .bottomLeft, .bottomRight], radius: 15, borderColor: self.grayColor, borderWidth: 1)
            })
        }
    }
}
  

Комментарии:

1. Какая-либо задача подъема в viewDidLoad или viewWillAppear появится в следующем контроллере просмотра?

2. только настройка (но ОЧЕНЬ тяжелая с несколькими UITableView.backgroundColor изменениями, изменениями нескольких UILable.textColor и другими)

3. Пожалуйста, опубликуйте этот код тоже.

4. обновлено, я знаю, что этот код не является удивительным D:

5. Я прокомментировал self.customization() , все еще задержка. Более того, я часто использую подобную навигацию, и это единственное место, где она имеет такую задержку.