I have some UIImageView
rotated (using the transform
property) in an app and I have noticed that on iOS17 the edges are heavily aliased, this is something I addressed originally by setting allowsEdgeAntialiasing
to true in the layer of those views and it has been working in other versions of iOS just fine.
This is how the view is set up
self.imageView.contentMode = .scaleAspectFill
self.imageView.clipsToBounds = true
self.imageView.backgroundColor = theme.BackgroundColor
self.imageView.layer.borderWidth = theme.BorderSize
self.imageView.alpha = theme.Alpha
self.imageView.layer.borderColor = theme.BorderColor.cgColor
self.imageView.layer.allowsEdgeAntialiasing = true
I tried setting the antialiasing globally in the .info
file, but the result is the same. Setting allowsEdgeAntialiasing
to false in the view doesn’t change the render result.
iOS 16 screenshot:
iOS 17 screenshot:
Edit
Quick complete example showing the issue:
class EdgeAntialiasingVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let g = view.safeAreaLayoutGuide
let imageViewA = UIImageView()
let imageViewB = UIImageView()
let viewA = UIView()
let viewB = UIView()
let labelA = UILabel()
let labelB = UILabel()
[imageViewA, imageViewB, viewA, viewB].forEach { v in
v.backgroundColor = .red
v.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(v)
v.layer.transform = CATransform3DMakeRotation(-.pi * 0.05, 0.0, 0.0, 1.0)
NSLayoutConstraint.activate([
v.widthAnchor.constraint(equalToConstant: 20.0),
v.heightAnchor.constraint(equalToConstant: 30.0),
])
}
for (v, s) in zip([labelA, labelB], ["UIImageView", "UIView"]) {
v.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(v)
v.font = .systemFont(ofSize: 14.0, weight: .light)
v.text = s
}
NSLayoutConstraint.activate([
labelA.topAnchor.constraint(equalTo: g.topAnchor, constant: 20.0),
labelA.leadingAnchor.constraint(equalTo: g.leadingAnchor, constant: 20.0),
imageViewA.topAnchor.constraint(equalTo: labelA.bottomAnchor, constant: 4.0),
imageViewB.topAnchor.constraint(equalTo: labelA.bottomAnchor, constant: 4.0),
imageViewA.leadingAnchor.constraint(equalTo: g.leadingAnchor, constant: 20.0),
imageViewB.leadingAnchor.constraint(equalTo: imageViewA.trailingAnchor, constant: 20.0),
labelB.topAnchor.constraint(equalTo: imageViewA.bottomAnchor, constant: 12.0),
labelB.leadingAnchor.constraint(equalTo: g.leadingAnchor, constant: 20.0),
viewA.topAnchor.constraint(equalTo: labelB.bottomAnchor, constant: 4.0),
viewB.topAnchor.constraint(equalTo: labelB.bottomAnchor, constant: 4.0),
viewA.leadingAnchor.constraint(equalTo: g.leadingAnchor, constant: 20.0),
viewB.leadingAnchor.constraint(equalTo: viewA.trailingAnchor, constant: 20.0),
])
imageViewB.layer.allowsEdgeAntialiasing = true
viewB.layer.allowsEdgeAntialiasing = true
}
}
Two UIImageView
s, and two UIView
s … right-side views have .layer.allowsEdgeAntialiasing = true
:
on iOS 16 – UIImageView
and UIView
both antialias the edges:
on iOS 17 – only UIView
antialiases the edges:
Show us examples of what you’re seeing.
I am seeing aliased edges, on iOS 16 the same view and code looks smooth. I will post some pictures.
@DonMag updated with screenshots
I edited your question with a quick example that anyone can copy/paste/run and see exactly what the issue is. Makes it much more likely folks will give it a try and report back with either confirmation or a solution.
This appears to be either a) a bug, or b) an undocumented change.