ImageAnalysisInteraction
An interface that enables people to interact with recognized text, barcodes, and other objects in an image.
Declaration
@MainActor @objc final class ImageAnalysisInteractionMentioned in
Overview
This class enables people to interact with specific content types (ImageAnalysisInteraction.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
This class conforms to the UIInteraction protocol. To connect the interface with an image that your app displays, call addInteraction(_:) on your app’s image view and pass in a new instance of this class.
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:
interaction.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. If your image view isn’t an instance of UIImageView, your app needs to define the interactive area within the image by implementing the contentsRect(for:) method.
Topics
Creating an image interaction
Configuring an image interaction
delegateanalysisviewpreferredInteractionTypesImageAnalysisInteraction.InteractionTypesactiveInteractionTypes
Responding to view events
Accessing text information
textselectedTextselectedAttributedTexthasText(at:)hasActiveTextSelectionanalysisHasText(at:)hasDataDetector(at:)
Managing text selection
Accessing image subjects
Managing image subjects
Querying the interface state
liveTextButtonVisibleisSupplementaryInterfaceHiddenhasInteractiveItem(at:)hasSupplementaryInterface(at:)selectableItemsHighlighted
Customizing the interface
allowLongPressForDataDetectorsInTextModesetSupplementaryInterfaceHidden(_:animated:)supplementaryInterfaceContentInsetssupplementaryInterfaceFont