我是 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)
}
}
}
低负载屏幕
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/