ImageAnalysisOverlayView
A view that enables people to interact with recognized text, barcodes, and other objects in an image.
Declaration
@MainActor @objc final class ImageAnalysisOverlayViewMentioned in
Overview
This class enables people to interact with specific content types (ImageAnalysisOverlayView.InteractionTypes) that the framework identifies in an image. For example:
The Live Text interface enables them to select any text present in the image (textSelection), or invoke a URL (dataDetectors). The text selection UI offers framework-standard buttons for copying selected text, or looking it up on the web for more information.
The subject lift feature identifies a wide variety of objects, or subjects, in images with the imageSubject interaction type, and provides your app with an image of the objects with the background removed. The visualLookUp type supplements this feature by adding a button in the bottom corner of the view that people can click or tap for more information about the recognized subjects.
Configure the interface and begin interaction
To connect the interface with an image that your app displays, add a new instance of this class as a subview to your app’s image view.
Choose the items that the framework recognizes in an image by configuring the preferredInteractionTypes property. To recognize all types of content, specify the automatic option, or choose a combination of types by assigning an array:
overlayView.preferredInteractionTypes = [.textSelection, .imageSubject]To begin interaction, call one of the ImageAnalyzer class’s analyze methods, such as analyze(_:configuration:) and set the result onto this class’s analysis property.
You can take more control over the interaction or provide details about your app’s image view by implementing a delegate (ImageAnalysisInteractionDelegate) and assigning it to the delegate property. Your app needs to define the interactive area within the image either by setting the trackingImageView property, or by implementing the delegate’s contentsRect(for:) method.
Topics
Creating overlay views
Configuring overlay views
delegateanalysispreferredInteractionTypesImageAnalysisOverlayView.InteractionTypestrackingImageViewactiveInteractionTypes
Responding to view events
Accessing text information
textselectedTextselectedAttributedTexthasActiveTextSelectionanalysisHasText(at:)hasText(at:)hasDataDetector(at:)
Managing text selection
Accessing image subjects
Managing image subjects
Querying the interface state
liveTextButtonVisibleisSupplementaryInterfaceHiddenhasInteractiveItem(at:)hasSupplementaryInterface(at:)selectableItemsHighlighted
Customizing the interface
setSupplementaryInterfaceHidden(_:animated:)supplementaryInterfaceContentInsetssupplementaryInterfaceFontImageAnalysisOverlayView.MenuTag