ios - 当我在 Xcode 上移动屏幕时,为什么我看到文本较晚?

标签 ios swift xcode navigation storyboard

我是 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)
        }
    }

}

低负载屏幕

loading

Storyboard

storyboard

我是在屏幕右侧跑拖拽后,点击,点击后释放在屏幕上的一个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()}
                    }
                }

关于ios - 当我在 Xcode 上移动屏幕时,为什么我看到文本较晚?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57797689/

相关文章:

swift - UN用户通知中心。此应用程序不允许通知

ios - 关闭消息 View Controller

ios - 尝试使用 Quick 在项目中运行测试时出现段错误

XCode 6.3 警告 : synthesize property

ios - 在iOS中的UIView上连续按下手势

ios - UITextbox 和 Navigationcontroller

ios - 如何使用邮件邀请参加 iCloud 日历事件,iOS swift

swift - 使用 joinWithSeparator 穿插到数组中时“引用不明确”

ios - 需要有关安全区域布局的帮助

ios - 2018 年 11 月提交应用程序所需的 Xcode 和 MacOS 最低版本