这是我的一步
1初始化subVIEw
2将新的子视图添加到textVIEw
3设置自动布局
4 set cornerRadius(vIEw.frame.height / 2)
运行应用程序后,cornerRadius不会更改
然后我尝试打印subVIEw的框架,得到(0,0)
这是我的代码
required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) circelVIEw = UIVIEw() self.addSubvIEw(circelVIEw) circelVIEw.snp_makeConstraints(closure: { (make) -> VoID in make.size.equalTo(80) make.top.equalTo(self.snp_top) make.right.equalTo(self.snp_right) }) print(circelVIEw.frame) //get wrong frame circelVIEw.layer.cornerRadius = circelVIEw.frame.size.height / 2 circelVIEw.layer.masksToBounds = true}解决方法 在打印框架和设置角半径时,您的视图没有时间布局.添加autoLayout约束不会自动布局视图.
要获得正确的结果,您需要在布局视图后设置角半径.这将保证您的框架受autoLayout约束的约束.
为此,请在“vIEwDIDLayoutSubvIEws”中放置任何需要正确框架的代码:
overrIDe func vIEwDIDLayoutSubvIEws() { print(circelVIEw.frame) // The frame will have been set circelVIEw.layer.cornerRadius = circelVIEw.frame.size.height / 2}
vIEwDIDLayoutSubvIEws()是UIVIEwController上可以覆盖的方法,请查看文档here.
总结以上是内存溢出为你收集整理的使用snapkit设置autolayout后,iOS框架出错全部内容,希望文章能够帮你解决使用snapkit设置autolayout后,iOS框架出错所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)