gpt4 book ai didi

swift - 如何禁用 MacCatalyst 上的全屏按钮

转载 作者:行者123 更新时间:2023-12-05 00:46:44 28 4
gpt4 key购买 nike

UIWindow on macCatalyst with close, minimize and fullscreen buttons

目前,我有这个停止调整窗口大小:

#if targetEnvironment(macCatalyst)
windowScene.sizeRestrictions?.minimumSize = CGSize(width: 480, height: 900)
windowScene.sizeRestrictions?.maximumSize = CGSize(width: 480, height: 900)
#endif

let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()

全屏 按钮无论如何都会使其全屏显示。

最佳答案

这是另一种不需要 Objective-C、选择器或异步调用的方法。它也不需要目标宏,iOS 将简单地跳过 if let NSApplication。将其粘贴到首先出现的 View Controller 中。请注意,这会禁用所有窗口上的绿色全屏按钮。如果您想与众不同,请使用 Asperi 的 Swift 部分的想法。

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

func bitSet(_ bits: [Int]) -> UInt {
return bits.reduce(0) { $0 | (1 << $1) }
}

func property(_ property: String, object: NSObject, set: [Int], clear: [Int]) {
if let value = object.value(forKey: property) as? UInt {
object.setValue((value & ~bitSet(clear)) | bitSet(set), forKey: property)
}
}

// disable full-screen button
if let NSApplication = NSClassFromString("NSApplication") as? NSObject.Type,
let sharedApplication = NSApplication.value(forKeyPath: "sharedApplication") as? NSObject,
let windows = sharedApplication.value(forKeyPath: "windows") as? [NSObject]
{
for window in windows {
let resizable = 3
property("styleMask", object: window, set: [], clear: [resizable])
let fullScreenPrimary = 7
let fullScreenAuxiliary = 8
let fullScreenNone = 9
property("collectionBehavior", object: window, set: [fullScreenNone], clear: [fullScreenPrimary, fullScreenAuxiliary])
}
}
}

关于swift - 如何禁用 MacCatalyst 上的全屏按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59749105/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com