diff --git a/CordovaLib/Classes/Public/CDVPlugin.m b/CordovaLib/Classes/Public/CDVPlugin.m index a2da3b86d..2a657703e 100644 --- a/CordovaLib/Classes/Public/CDVPlugin.m +++ b/CordovaLib/Classes/Public/CDVPlugin.m @@ -21,7 +21,6 @@ Licensed to the Apache Software Foundation (ASF) under one #import #import "CDVPlugin+Private.h" #import -#include @implementation UIView (org_apache_cordova_UIView_Extension) @@ -29,12 +28,9 @@ @implementation UIView (org_apache_cordova_UIView_Extension) - (UIScrollView*)scrollView { - SEL scrollViewSelector = NSSelectorFromString(@"scrollView"); - - if ([self respondsToSelector:scrollViewSelector]) { - return ((id (*)(id, SEL))objc_msgSend)(self, scrollViewSelector); + if ([self respondsToSelector:@selector(scrollView)]) { + return [self performSelector:@selector(scrollView)]; } - return nil; } diff --git a/CordovaLib/Classes/Public/CDVViewController.m b/CordovaLib/Classes/Public/CDVViewController.m index 8cf9f2489..a30671da0 100644 --- a/CordovaLib/Classes/Public/CDVViewController.m +++ b/CordovaLib/Classes/Public/CDVViewController.m @@ -17,10 +17,10 @@ Licensed to the Apache Software Foundation (ASF) under one under the License. */ +#import #import #import #import -#import #import #import @@ -373,6 +373,30 @@ -(void)viewWillAppear:(BOOL)animated -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; + +#if TARGET_OS_MACCATALYST + BOOL hideTitlebar = [self.settings cordovaBoolSettingForKey:@"HideDesktopTitlebar" defaultValue:NO]; + if (hideTitlebar) { + UIWindowScene *scene = self.view.window.windowScene; + if (scene) { + scene.titlebar.titleVisibility = UITitlebarTitleVisibilityHidden; + scene.titlebar.toolbar = nil; + } + } else { + // We need to fix the web content going behind the title bar + self.webView.translatesAutoresizingMaskIntoConstraints = NO; + [self.webView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor].active = YES; + [self.webView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor].active = YES; + [self.webView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor].active = YES; + [self.webView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = YES; + + if ([self.webView respondsToSelector:@selector(scrollView)]) { + UIScrollView *scrollView = [self.webView performSelector:@selector(scrollView)]; + scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; + } + } +#endif + [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVViewDidAppearNotification object:nil]]; }