...init() { label = UILabel() label.translatesautoresizingMaskIntoConstraints = false self.translatesautoresizingMaskIntoConstraints = false addSubvIEw(label) self.layer.masksToBounds = false self.layer.shadowcolor = UIcolor.blackcolor().CGcolor self.layer.shadowOpacity = 1.0 self.layer.shadowRadius = 2.0 // Adding these lines trying to explicitly stop shadow on label... label.layer.shadowOpacity = 0 label.layer.shadowcolor = nil ...}解决方法 当父视图的Alpha值小于1.0或没有背景颜色(即设置为清除颜色)时,会发生这种情况.在这种情况下,阴影转换为子视图.有关详细信息,请参阅我的答案 here.
苹果Docs证明了这一点:
总结figure A-7 shows several different versions of the same sample layer with a red shadow applIEd. The left and mIDdle versions include a background color so the shadow appears only around the border of the layer. However,the version on the right does not include a background color. In this case,the shadow is applIEd to the layer’s content,border,and sublayers.
以上是内存溢出为你收集整理的ios – 停止CALayer影子影响子视图?全部内容,希望文章能够帮你解决ios – 停止CALayer影子影响子视图?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)