为什么我在 Xcode 上移动屏幕时看到文本晚了?

Why do I see the text late when I move the screen on Xcode?

我是 iOS 开发的初学者。开发当前项目时出现问题。移动屏幕时字符会显示得太晚。我只是 运行 一个正常的屏幕切换。为什么会这样?

startViewController.swift

    @IBAction func Onclick(_ sender: Any) {
        AVCaptureDevice.requestAccess(for: AVMediaType.video) { response in
            if response {
                print(response , ": granted")
                let center = UNUserNotificationCenter.current()
                // Request permission to display alerts and play sounds.
                center.requestAuthorization(options: [.alert, .sound])
                { (granted, error) in
                    if granted {
                        print(granted, ": is granted")
                        self.moveScreen()
                    } else {
                        print(granted, ": is not granted")
                        self.moveScreen()
                    }
                }
            } else {
                print(response , ": not granted")
                let center = UNUserNotificationCenter.current()
                // Request permission to display alerts and play sounds.
                center.requestAuthorization(options: [.alert, .sound])
                { (granted, error) in
                    if error == nil {
                        if granted == true {
                             print(granted, ": is granted")
                             self.moveScreen()
                        }
                        else {
                            print(granted, ": is not granted")
                            self.moveScreen()
                        }
                    } else {
                        print(error as Any)
                        }
                }

            }
        }
    }

    func moveScreen(){
        let mainViewScreen = self.storyboard?.instantiateViewController(withIdentifier: "MainViewController")
        mainViewScreen?.modalTransitionStyle = UIModalTransitionStyle.coverVertical
        self.present(mainViewScreen!, animated: true, completion: nil)
    }

MainViewController.swift

import Foundation
import UIKit


class MainViewController: UIViewController {

    @IBOutlet weak var mainLogo: UIImageView!
    @IBOutlet weak var mainText: UITextView!
    @IBOutlet weak var mainSecondText: UITextView!
    @IBOutlet weak var takeWalletText: UIButton!
    @IBOutlet weak var makeWalletText: UIButton!


    @IBAction func takeWallet(_ sender: Any) {
    }

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

    func changeFontSize() {
        let screenWidth = UIScreen.main.bounds.size.width
        let screenHeight = UIScreen.main.bounds.size.height

        if screenWidth < 375 {
            // iPhone 4inch and 3.5inch. Smaller than iPhone 8
            // Call change font
            mainText.font = UIFont.systemFont(ofSize: 16)
            mainSecondText.font = UIFont.systemFont(ofSize: 12)

            takeWalletText.titleLabel?.font = UIFont.systemFont(ofSize: 14)
            makeWalletText.titleLabel?.font = UIFont.systemFont(ofSize: 14)

        }
        if screenHeight > 667 {

            mainText.font = UIFont.systemFont(ofSize: 20)
            mainSecondText.font = UIFont.systemFont(ofSize: 16)

            takeWalletText.titleLabel?.font = UIFont.systemFont(ofSize: 16)
            makeWalletText.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        }
    }

}

低加载屏幕

故事板

我是在屏幕上运行拖拽后,点一下,在屏幕上松开后点了一个show就移动了。

提前致谢

我在 @Paulw11 的帮助下解决了这个问题。我的问题是,当我设置 NSNotification 时,我将其作为异步请求调用。这就是为什么我的屏幕会延迟文本消息延迟出现的原因。这通过异步交换函数执行来解决。

                center.requestAuthorization(options: [.alert, .sound])
                { (granted, error) in
                    if granted {
                        print(granted, ": is granted")
                        DispatchQueue.main.async { self.moveScreen()}
                    } else {
                        print(granted, ": is not granted")
                        DispatchQueue.main.async { self.moveScreen()}
                    }
                }