以下是官方链接:https://developer.apple.com/documentation/uikit/mac_catalyst/removing_the_title_bar_in_your_mac_app_built_with_mac_catalyst?language=objc
我不知道如何将代码翻译成Objective-C。页面顶部有一个选项,但它不起作用。
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
#if targetEnvironment(macCatalyst)
if let titlebar = windowScene.titlebar {
titlebar.titleVisibility = .hidden
titlebar.toolbar = nil
}
#endif
}
内部SceneDelegate.h将此代码添加到场景:WillConnectToSession:选项:方法:
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
#if TARGET_OS_MACCATALYST
// Code specific to Mac.
[(UIWindowScene *)scene titlebar].titleVisibility = UITitlebarTitleVisibilityHidden;
[(UIWindowScene *)scene titlebar].toolbar = nil;
#else
// Code to exclude from Mac.
#endif
}
它有效。