我正在试图在我的视图控制器中的uiview的所有四个面上建立一个阴影,在我通过xcode向uiview添加约束之前,它工作得非常好。如何使uiview的阴影显示在所有四个边上,并为所有边设置约束?
本质上,我发现,每当我通过xcode对我设置了阴影的uiview应用约束时,阴影不会出现在uiview的所有四个边下。相反,它漂浮到左侧,完全离开右侧和底部,没有阴影。这可以在下面的屏幕截图中看到。
class RegistrationViewController: UIViewController {
@IBOutlet weak var signUpView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
signUpView.clipsToBounds = true
signUpView.layer.cornerRadius = 20;
signUpView.layer.shadowPath = UIBezierPath(roundedRect: signUpView.bounds, cornerRadius: signUpView.layer.cornerRadius).cgPath
signUpView.layer.shouldRasterize = true
signUpView.layer.shadowColor = UIColor.black.cgColor
signUpView.layer.shadowOffset = .zero
signUpView.layer.shadowOpacity = 1
signUpView.layer.shadowRadius = 20
signUpView.layer.masksToBounds = false
// Do any additional setup after loading the view.
}
}
为什么会发生这种情况?如何在保持预期结果的同时添加约束?