我正在屏幕上工作,我想让这个配置文件视图循环。但是我没有从中获得高度或宽度imageView.frame.height以在layer.cornerRadius. 请帮我。谢谢。
这是代码供参考。
private func addImageView() {
topView.addSubview(profilePicView)
NSLayoutConstraint.activate([
profilePicView.centerXAnchor.constraint(equalTo: topView.centerXAnchor),
profilePicView.widthAnchor.constraint(equalTo: topView.heightAnchor, multiplier: 0.3)
])
profilePicViewTopAnchor = profilePicView.topAnchor.constraint(equalTo: view.topAnchor, constant: 64)
profilePicViewTopAnchor?.isActive = true
profilePicViewHeightAnchor = profilePicView.heightAnchor.constraint(equalTo: topView.heightAnchor, multiplier: 0.3)
profilePicViewHeightAnchor?.isActive = true
}
Run Code Online (Sandbox Code Playgroud)
我试图获得价值,
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
print((profilePicViewHeightAnchor?.constant)!)
profilePicView.layer.cornerRadius = (profilePicViewHeightAnchor?.constant)! / 2
profilePicView.clipsToBounds = true
}
Run Code Online (Sandbox Code Playgroud)
解决了
在大家的帮助下,我得到了这个对我来说非常适合的解决方案,
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
let radius = redView.frame.height * 0.3
profilePicView.layer.cornerRadius = radius / 2
profilePicView.clipsToBounds = true
self.view.layoutIfNeeded()
}
Run Code Online (Sandbox Code Playgroud)
感谢你们所有人。真的很感谢帮助。