supportsZoom
The accessibility element supports zooming in and out on its content.
Declaration
nonisolated static let supportsZoom: UIAccessibilityTraitsDiscussion
Use this trait to characterize an accessibility element that supports zoom functionality, like letting a person perform expand and pinch gestures to zoom in and out. If you assign this trait to an element, you also need to implement accessibilityZoomIn(at:) and accessibilityZoomOut(at:).
For example, the following code shows how to assign this trait to a custom view that allows zooming in to an image:
class ViewController: UIViewController {
let zoomView = ZoomingImageView(frame: .zero)
let imageView = UIImageView(image: UIImage(named: "tree"))
override func viewDidLoad() {
super.viewDidLoad()
zoomView.isAccessibilityElement = true
zoomView.accessibilityLabel = "Zooming Image View"
zoomView.accessibilityTraits = [.image, .supportsZoom]
zoomView.addSubview(imageView)
view.addSubview(zoomView)
}
}This custom view implements the required methods to modify the zoom scale and post an announcement about the new zoom scale.
class ZoomingImageView: UIScrollView {
override func accessibilityZoomIn(at point: CGPoint) -> Bool {
zoomScale += 1.0
let zoomQuantity = "\(Int(zoomScale)) x zoom"
UIAccessibility.post(notification: .announcement, argument: zoomQuantity)
return true
}
override func accessibilityZoomOut(at point: CGPoint) -> Bool {
zoomScale -= 1.0
let zoomQuantity = "\(Int(zoomScale)) x zoom"
UIAccessibility.post(notification: .announcement, argument: zoomQuantity)
return true
}
}