本文介绍了Snapkit和UILabel的轮换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有:
- UIView(容器)
- UIView. (1)的子视图-下图中的深蓝色
- UIView. (1)的子视图-下图中的紫色
- UILabel. edge.equalToSuperview()
我要完成的工作:
问题是,我希望UILabel旋转3pi/2(270°).一旦完成旋转,就无法正确放置它.
The thing is, I want the UILabel to be rotated 3pi/2 (270°). Once I've done the rotation, it isn't placed correctly.
这是通过设置edge.equalToSuperview()和270°旋转的样子:
This is how it looks like by setting edges.equalToSuperview() and the 270°rotation:
我已经尝试过了(但是会导致崩溃):
I've tried this (but it leads to a crash):
myLabel.makeConstraints { make in
make.top.equalTo(containerView.snp.left)
make.right.equalTo(containerView.snp.top)
make.left.equalTo(containerView.snp.bottom)
make.bottom.equalTo(containerView.snp.right)
}
崩溃说明:
*** Terminating app due to uncaught exception 'NSInvalidLayoutConstraintException', reason: 'Constraint improperly relates anchors of incompatible types: <SnapKit.LayoutConstraint:[email protected]#250 MyProject.MyLabel:0x7fcc2201ca80.top == UIView:0x7fcc2201bd30.left>'
有什么想法我可以在这里做什么?
Any ideas what I could do here?
推荐答案
对于使用Snapkit对elk_cloner的答案感兴趣的任何人:
For anyone interested in elk_cloner's answer using Snapkit:
myLabel.snp.makeConstraints { make in
make.centerX.equalTo(containerView.snp.centerX)
make.centerY.equalTo(containerView.snp.centerY)
}
这篇关于Snapkit和UILabel的轮换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!