直到昨天我将 Xcode 更新到版本 8 之前,一切都很好。
如果我不使用任何约束,我可以看到按钮,但是当我对按钮应用约束时,它们会消失,无论约束是什么或多少(高度、垂直间距、拖尾等...)我申请。
当我点击按钮时,它们表现正常(事件总是被发送所以我假设它们实际上位于那里(?))。我尝试更改文本颜色、背景颜色(甚至添加新的 UIButton),但没有成功。我看不到按钮。当我更改 居中 View 的背景颜色时,我可以在应用程序上看到此更改。最奇怪的部分是当我在 Xcode 上单击 Debug View Hierarchy 以查看发生了什么时,一切看起来都很好;我可以看到所有按钮的位置都符合我的预期。
在 iPhone 5 (iOS 9.3.5) 和 iPhone 6 (iOS 10) 上测试该应用。
我使用的是 Swift 2.3、iOS 10 和 Xcode 8。
这是 Xcode 8 上的错误吗?如何解决这个问题?
更新:
我刚刚意识到在 UILabel 和 UIImageView 上也出现了同样的约束问题。它们在没有约束的情况下看起来很好,但是当我添加任何约束时它们就会消失。
最佳答案
通过在设置任何与布局相关的属性(如 clipToBounds 等)之前强制布局来解决此问题...棘手的部分是调用 layoutIfNeeded 的位置和时间。
在我的例子中,我有一个带有水平、顶部和高度约束的 UIButton。显然在 Xcode 8 上,我的按钮标题突然消失了。然后奇怪的是,在我删除高度限制后标题出现了。此行为表明可能在 View 的布局周期内存在问题。我需要有高度限制,所以删除它并不是真正的解决方案。所以我尝试在设置约束之前调用 layoutIfNeeded 但没有效果。
我通过处理它的 NSObject 类在 Controller 上的 viewDidLoad 上生成了这个按钮。我的解决方案是在调用设置按钮的方法之前强制执行 layoutIfNeeded。
- (void)viewDidLoad {
[super viewDidLoad];
[self.view layoutIfNeeded];
//editBooking - NSObject class where the button gets configured.
[_editBooking setUpViews];
}
相关问题:clipsToBounds causes UIImage to not display in iOS10 & XCode 8
编辑:
"I think the (0, 0, 1000, 1000) bound initialization is the new way Xcode instanciates views from IB. Before Xcode8, views were created with their configured size in the xib, then resized according to screen just after. But now, there is no configured size in IB document since the size depends on your device selection (at the bottom of the screen)."
引用:Since Xcode 8 and iOS10, views are not sized properly on viewDidLayoutSubviews
来自 Apple 发行说明:
Sending layoutIfNeeded to a view is not expected to move the view, but in earlier releases, if the view had translatesAutoresizingMaskIntoConstraints set to NO, and if it was being positioned by constraints, layoutIfNeeded would move the view to match the layout engine before sending layout to the subtree. These changes correct this behavior, and the receiver’s position and usually its size won’t be affected by layoutIfNeeded.
Some existing code may be relying on this incorrect behavior that is now corrected. There is no behavior change for binaries linked before iOS 10, but when building on iOS 10 you may need to correct some situations by sending -layoutIfNeeded to a superview of the translatesAutoresizingMaskIntoConstraints view that was the previous receiver, or else positioning and sizing it before (or after, depending on your desired behavior) layoutIfNeeded.
关于ios - 带有约束的 Xcode 8 UIButtons 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39503572/
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格: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
我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的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返回它复制的字节数,但是当我还没有下
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
目前,Itembelongs_toCompany和has_manyItemVariants。我正在尝试使用嵌套的fields_for通过Item表单添加ItemVariant字段,但是使用:item_variants不显示该表单。只有当我使用单数时才会显示。我检查了我的关联,它们似乎是正确的,这可能与嵌套在公司下的项目有关,还是我遗漏了其他东西?提前致谢。注意:下面的代码片段中省略了不相关的代码。编辑:不知道这是否相关,但我正在使用CanCan进行身份验证。routes.rbresources:companiesdoresources:itemsenditem.rbclassItemi
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里