• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - 为什么我的模拟以编程方式获得与 anchor /约束有关的空白黑屏?

[复制链接]
菜鸟教程小白 发表于 2022-12-11 18:18:03 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

这是我的代码。我试图将 webView anchor 的顶部限制在 View Controller 顶部布局指南的底部,但我只是得到一个黑屏,有时控制台中出现 错误:

 Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<_UILayoutSupportConstraint:0x608000284d30 _UILayoutSpacer:0x6080001aa560'UIVC-topLayoutGuide'.height == 20   (active)>",
    "<_UILayoutSupportConstraint:0x6080002850a0 V:|-(0)-[_UILayoutSpacer:0x6080001aa560'UIVC-topLayoutGuide']   (active, names: '|':UIView:0x7fcfcac26cd0 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x608000280fa0 h=--& v=--& WKWebView:0x7fcfcb09a400.midY == 0   (active)>",
    "<NSAutoresizingMaskLayoutConstraint:0x608000280ff0 h=--& v=--& WKWebView:0x7fcfcb09a400.height == 0   (active)>",
    "<NSLayoutConstraint:0x6080002846f0 V:[_UILayoutSpacer:0x6080001aa560'UIVC-topLayoutGuide']-(3)-[WKWebView:0x7fcfcb09a400]   (active)>",
    "<NSAutoresizingMaskLayoutConstraint:0x608000281220 h=--& v=--& 'UIView-Encapsulated-Layout-Top' UIView:0x7fcfcac26cd0.minY == 0   (active, names: '|':UIViewControllerWrapperView:0x7fcfcac08120 )>"
)

代码 -

import UIKit
import WebKit

class webViewController: UIViewController, WKNavigationDelegate {

    override func loadView() {
        self.view = UIView()
        let webView = WKWebView()
//        webView.translatesAutoresizingMaskIntoConstraints = false
        self.view.addSubview(webView)

        let topConstraint = webView.topAnchor.constraint(equalTo: self.topLayoutGuide.bottomAnchor, constant: 3)
        topConstraint.isActive = true

        let url = NSURL(string: "https://www.google.com")
        if let selectedURL = url {
            let request = NSURLRequest(url: selectedURL as URL) as URLRequest
            webView.load(request)
        }
    }
}



Best Answer-推荐答案


添加导航委托(delegate):

webView.navigationDelegate = self

然后听错误和导航代表,你将能够看到真正发生或没有发生的事情。

关于ios - 为什么我的模拟以编程方式获得与 anchor /约束有关的空白黑屏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41045099/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap