我正在将 ViewController 推到我当前的 ViewController 之上。
我想推送的 ViewController 是一个 WebView,但我想这无关紧要。
我不希望呈现的 ViewController 位于状态栏下方。但是我该如何设置这些约束呢?
这是我加载推送的 ViewController 的代码:
@objc func loadWebView(sender: UIButton) {
let vc = WebViewVC()
webViewVC = vc
self.present(webViewVC!, animated: true, completion: nil)
}
如果我为 webViewVC.view 设置与父 ViewController 的 View 相关的约束,它当然会告诉我这是不允许的,因为 View 位于不同的 View 层次结构中。
这是我在 WebViewVC 中设置布局的方式:
func setUpView() {
let view = UIView()
self.view = view
view.st(navigationBar,webView)
navigationBar.heightAnchor.constraint(equalTo: webView.heightAnchor, multiplier: 0.1).isActive = true
navigationBar.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
navigationBar.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0).isActive = true
navigationBar.topAnchor.constraint(equalTo: view.topAnchor, constant: 0).isActive = true
navigationBar.bottomAnchor.constraint(equalTo: webView.topAnchor, constant: 0).isActive = true
webView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
webView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0).isActive = true
webView.topAnchor.constraint(equalTo: navigationBar.bottomAnchor, constant: 0).isActive = true
webView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0).isActive = true
}
最佳答案
根据苹果文档:
The layout guide representing the portion of your view that is unobscured by bars and other content.
更改导航栏顶部 anchor :
if #available(iOS 11, *) {
let guide = view.safeAreaLayoutGuide
navigationBar.topAnchor.constraint(equalTo: guide.topAnchor).isActive = true
} else {
navigationBar.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor).isActive = true
}
关于ios - 为显示的 ViewController 设置约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52963082/
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我正在查看instance_variable_set的文档并看到给出的示例代码是这样做的:obj.instance_variable_set(:@instnc_var,"valuefortheinstancevariable")然后允许您在类的任何实例方法中以@instnc_var的形式访问该变量。我想知道为什么在@instnc_var之前需要一个冒号:。冒号有什么作用? 最佳答案 我的第一直觉是告诉你不要使用instance_variable_set除非你真的知道你用它做什么。它本质上是一种元编程工具或绕过实例变量可见性的黑客攻击
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下