在UIViewController
上,我们可以很容易地将观测器添加到控制器中。比如:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(didTakeScreenshot(notification:)), name: UIApplication.userDidTakeScreenshotNotification, object: nil)
}
@objc func didTakeScreenshot(notification: Notification) {
print("Screen Shot Taken")
}
}
字符串
或捕获记录:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let isCaptured = UIScreen.main.isCaptured
return true
}
型
如何使用SwiftUI?
2条答案
按热度按时间ifsvaxew1#
下面是一个简单的demo:
字符串
k4aesqcs2#
现在你可能想要
EnvironmentValues.isSceneCaptured
iOS 17及以后