【发布时间】:2021-06-10 10:17:27
【问题描述】:
我有一个使用 Objective C 的旧 iOS 项目。当我将 WKWebView 添加到 ViewController 时
NSURL *url = [NSURL URLWithString:@"https://www.google.com"];
WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
_webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:theConfiguration];
[self.view addSubview:_webView];
self.webView.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[
[self.webView.topAnchor constraintEqualToAnchor:self.view.topAnchor],
[self.webView.leftAnchor constraintEqualToAnchor:self.view.leftAnchor],
[self.webView.rightAnchor constraintEqualToAnchor:self.view.rightAnchor],
[self.webView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor]
]];
[_webView loadRequest:[NSURLRequest requestWithURL:url]];
如果我在 iOS 14 中通过 Xcode 安装应用程序,webview 工作正常,但在我断开 Xcode 并直接打开应用程序后,webview 显示内容的框架错误。如果我通过 Xcode 在 iOS 12.5 中构建应用程序,Web 视图也会显示错误框架的内容。 如果我从 Xcode 12.5 创建新项目并使用相同的代码,它工作正常。
这是通过 Xcode 构建打开应用时的屏幕截图
https://i.stack.imgur.com/rYb3M.png
这是直接打开应用时的截图:
【问题讨论】:
标签: ios objective-c xcode wkwebview