fix 修复ios toolbar 完成按钮失效的问题

This commit is contained in:
zher52 2020-09-17 16:36:16 +08:00
parent b8e87a8b1d
commit 694ffb52eb
2 changed files with 15 additions and 9 deletions

View File

@ -56,6 +56,7 @@
NSDictionary *_settings; NSDictionary *_settings;
} }
@property (nonatomic, strong) IBOutlet UIViewController* parent;
@property (nonatomic, strong) IBOutlet WKWebView* webView; @property (nonatomic, strong) IBOutlet WKWebView* webView;
@property (nonatomic, strong) IBOutlet WKWebViewConfiguration* configuration; @property (nonatomic, strong) IBOutlet WKWebViewConfiguration* configuration;
@property (nonatomic, strong) IBOutlet UIBarButtonItem* closeButton; @property (nonatomic, strong) IBOutlet UIBarButtonItem* closeButton;
@ -76,6 +77,6 @@
- (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition; - (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition;
- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) buttonIndex; - (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) buttonIndex;
- (id)initWithBrowserOptions: (CDVInAppBrowserOptions*) browserOptions andSettings:(NSDictionary*) settings; - (id)initWithBrowserOptions: (CDVInAppBrowserOptions*) browserOptions andSettings:(NSDictionary*) settings andParent:(UIViewController*) parent;
@end @end

View File

@ -74,11 +74,7 @@ static CDVWKInAppBrowser* instance = nil;
NSLog(@"IAB.close() called but it was already closed."); NSLog(@"IAB.close() called but it was already closed.");
return; return;
} }
UIView *lastView;
for(UIView *subview in [self.viewController.view subviews]) {
lastView = subview;
}
[lastView removeFromSuperview];
// Things are cleaned up in browserExit. // Things are cleaned up in browserExit.
[self.inAppBrowserViewController close]; [self.inAppBrowserViewController close];
} }
@ -203,7 +199,7 @@ static CDVWKInAppBrowser* instance = nil;
} }
if (self.inAppBrowserViewController == nil) { if (self.inAppBrowserViewController == nil) {
self.inAppBrowserViewController = [[CDVWKInAppBrowserViewController alloc] initWithBrowserOptions: browserOptions andSettings:self.commandDelegate.settings]; self.inAppBrowserViewController = [[CDVWKInAppBrowserViewController alloc] initWithBrowserOptions: browserOptions andSettings:self.commandDelegate.settings andParent: self.viewController];
self.inAppBrowserViewController.navigationDelegate = self; self.inAppBrowserViewController.navigationDelegate = self;
if ([self.viewController conformsToProtocol:@protocol(CDVScreenOrientationDelegate)]) { if ([self.viewController conformsToProtocol:@protocol(CDVScreenOrientationDelegate)]) {
@ -716,7 +712,7 @@ static CDVWKInAppBrowser* instance = nil;
BOOL viewRenderedAtLeastOnce = FALSE; BOOL viewRenderedAtLeastOnce = FALSE;
BOOL isExiting = FALSE; BOOL isExiting = FALSE;
- (id)initWithBrowserOptions: (CDVInAppBrowserOptions*) browserOptions andSettings:(NSDictionary *)settings - (id)initWithBrowserOptions: (CDVInAppBrowserOptions*) browserOptions andSettings:(NSDictionary *)settings andParent:(UIViewController*) parent
{ {
self = [super init]; self = [super init];
if (self != nil) { if (self != nil) {
@ -724,7 +720,7 @@ BOOL isExiting = FALSE;
_settings = settings; _settings = settings;
self.webViewUIDelegate = [[CDVWKInAppBrowserUIDelegate alloc] initWithTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]]; self.webViewUIDelegate = [[CDVWKInAppBrowserUIDelegate alloc] initWithTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]];
[self.webViewUIDelegate setViewController:self]; [self.webViewUIDelegate setViewController:self];
self.parent = parent;
[self createViews]; [self createViews];
} }
@ -1079,14 +1075,23 @@ BOOL isExiting = FALSE;
return NO; return NO;
} }
- (void)newClose{
}
- (void)close - (void)close
{ {
self.currentURL = nil; self.currentURL = nil;
__weak UIViewController* weakSelf = self; __weak UIViewController* weakSelf = self;
__weak UIViewController* weakParentSelf = self.parent;
// Run later to avoid the "took a long time" log message. // Run later to avoid the "took a long time" log message.
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
UIView *lastView;
for(UIView *subview in [weakParentSelf.view subviews]) {
lastView = subview;
}
[lastView removeFromSuperview];
isExiting = TRUE; isExiting = TRUE;
if ([weakSelf respondsToSelector:@selector(presentingViewController)]) { if ([weakSelf respondsToSelector:@selector(presentingViewController)]) {
[[weakSelf presentingViewController] dismissViewControllerAnimated:YES completion:nil]; [[weakSelf presentingViewController] dismissViewControllerAnimated:YES completion:nil];