所以我在过去的 5-6 个小时里试图让这个功能发挥作用,但我在实施过程中遇到了一些陷阱和理解的限制。我尝试了几种方法:
方法一:
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
self.window = UIWindow(frame: UIScreen.main.bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
var vc : UIViewController
vc = storyboard.instantiateViewController(withIdentifier: "PasscodeLockVC")
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()
print("app entered foreground")
}
问题:我无法从 PasscodeLockVC 关闭屏幕(它是密码 VC)。
方法二:
public extension UIViewController {
func show() {
let win = UIWindow(frame: UIScreen.main.bounds)
let vc = UIViewController()
vc.view.backgroundColor = .clear
win.rootViewController = vc
win.windowLevel = UIWindowLevelAlert + 1
win.makeKeyAndVisible()
vc.present(self, animated: true, completion: nil)
}
func hide() {
dismiss(animated: true, completion: nil)
}
}
问题:我解雇时出现黑屏。
**所以我的问题是**有人可以指导我在进入前台时让我的锁屏出现的最佳方法(我知道它进入 applicationWillEnterForegroud),但是当我这样做时,它会保留应用程序时处于活动状态的屏幕被关闭了(因为它是一个日记应用程序,所以它的所有内容都会)?我整天都被难住了,真的可以使用一些方向。
在最新的 Xcode 上运行