前言:最近开始着手使用swift语言,遇到一些坑,特此记录
- 问题如下
- 中间菱形通过UIView旋转45度得到,但是右上右下边边很明显的看到变细(此图是通过Debug View Hierarchy放大看到),原以为是阴影设置,但是经过测试发现不是,问题依然存在
fileprivate let squareView: UIView = {
let squareView = UIView()
squareView.layer.borderColor = UIColor.black.cgColor
squareView.layer.borderWidth = 2.0
squareView.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi / 4))
return squareView
}()
问题截图.jpg
- 目前的解决方案
fileprivate let squareView: UIView = {
let squareView = UIView()
return squareView
}()
let path = CGMutablePath()
path.addRect(squareView.bounds)
squareLayer.path = path
squareView.layer.addSublayer(squareLayer)
squareView.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi / 4))
现在.jpg
虽然通过添加layer方式问题得到解决,但是始终不明白直接设置layer边框再旋转,边框变细的原因,等之后搞明白了,再来更新O(∩_∩)O哈哈~
网友评论