问题描述
我有一个带有XIB的视图控制器,内部有一个视图(contentView
).该视图包含一些按钮.
I have a view controller with XIB, with a view (contentView
) inside. This view contains some buttons.
内容视图具有圆角和边界剪辑,但它不遵守剪切矩形.我在视图控制器的viewDidLoad
中设置了转角半径和clipsToBounds
.
The content view has round corners and clips to bounds, but it doesn't respect the clipping rect. I set the corner radius and the clipsToBounds
in the viewDidLoad
of the view controller.
在这里您可以看到显示屏幕截图,该屏幕截图显示了视图的构成方式正确,但是在模拟器和设备上的裁剪范围没有得到遵守.
Here you can see the reveal screenshot that shows that the view is composed in the correct way, but on simulator and device clipping bounds are not respected.
任何人都可以帮助我了解发生了什么.
Anybody can please help me to understand what happen.
该应用程序针对iOS 10和11,并且都存在相同的问题.
The app is targeted to iOS 10 and 11, and both have the same issue.
推荐答案
我找到了一个解决方案,我将clipsToBound移到了viewDidLayoutSubviews而不是viewDidLoad中,现在可以工作了
I found a solution, I move the clipsToBound in the viewDidLayoutSubviews instead viewDidLoad and now works
override func viewDidLoad() {
super.viewDidLoad()
contentView.layer.cornerRadius = Dimensions.CornerRaius
contentView.dropShadow()
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
contentView.clipsToBounds = true
}
这篇关于UIView clipsToBounds不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!