在视图下方可见相同的角半径 [英] Same cornerRadius is visible underneath the view

查看:68
本文介绍了在视图下方可见相同的角半径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将彼此相同的 cornerRadius 放置在 UIViews 上,则可以在顶部(黄色)的拐角附近看到底部(红色)视图看法.有可能修复它吗?

If I place to UIViews with the same cornerRadius on top of each other, I can see the bottom (red) view near the corners of the top (yellow) view. Is it possible to fix it?

let rectFrame = CGRect(x:50, y:100, width: 150, height: 150)
let cornerRadius: CGFloat = 10.0

let redView = UIView(frame:rectFrame)
redView.backgroundColor = .red
redView.layer.cornerRadius = cornerRadius

let yellowView = UIView(frame: rectFrame)
yellowView.backgroundColor = .yellow
yellowView.layer.cornerRadius = cornerRadius

view.addSubview(redView)
view.addSubview(yellowView)

角落(缩放):

推荐答案

这是 antialiasing 的结果.这两个视图都有一些包含曲线的半透明像素.即使不是,也可以使曲线看起来平滑(因为像素为正方形).

That is a result of antialiasing. Both views have some semitransparent pixels comprising the curve. It makes the curve look smooth even though it isn’t (because pixels are square).

您可以关闭抗锯齿以绘制图层,但我建议您不要这样做.使后视图不可见会更简单.

You could turn off antialiasing for the drawing of the layers, but I’d advise against that. It would be simpler to make the rear view invisible.

这篇关于在视图下方可见相同的角半径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆