当应用程序处于后台时,WKWebView会显示黑屏

时间:2020-04-29 14:14:42

标签: ios objective-c xcode wkwebview

我最近在Xcode中将UIWebView更改为WKWebView,到目前为止一切正常。 但是,当我在IBs属性检查器中使用“链接预览”(对我来说非常有用的功能)复选标记字段时,该应用程序在后台时会完全变黑。 这意味着用户要再次使用它时必须杀死它。

这是WebViewController的代码:

@interface WebViewController ()

@end

@implementation WebViewController
@synthesize activityIndicatorView = _activityIndicatorView;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        NSLog(@"Webview");
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    _webView.UIDelegate = self;
    _webView.navigationDelegate = self;


    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.webLink]]];


    [self setupConstraints];

}


-(void)setupConstraints {
    [self.webView setTranslatesAutoresizingMaskIntoConstraints:NO];

    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.webView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view.safeAreaLayoutGuide attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.webView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.webView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0.0]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.webView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view.safeAreaLayoutGuide attribute:NSLayoutAttributeHeight multiplier:1.0 constant:0.0]];
}


@end

这就是我从tableView调用WKWebViewController的方式:

 WebViewController *webVC = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];

                        webVC.webLink = str;

                        [self.navigationController pushViewController:webVC animated:YES];



在什么情况下如何防止控制器变黑 “链接预览”已打开,并且应用程序在后台运行后又回来了?

(Xcode 11.4.1,目标iOS 11)

非常感谢! 马丁

0 个答案:

没有答案