One Logo Pool Ball
VisionKit · IOS API REFERENCE

ImageAnalysisInteraction

class · iOS 16.0+ · SDK 27.1

@MainActor @objc final class ImageAnalysisInteraction

An interface that enables people to interact with recognized text, barcodes, and other objects in an image. 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 (``ImageAnalysisInteraction/InteractionTypes/textSelection``), or invoke a URL (``ImageAnalysisInteraction/InteractionTypes/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 ``ImageAnalysisInteraction/InteractionTypes/imageSubject`` interaction type, and provides your app with an image of the objects with the background removed. The ``ImageAnalysisInteraction/InteractionTypes/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 <doc://com.apple.documentation/documentation/uikit/uiinteraction> protocol. To connect the interface with an image that your app displays, call <doc://com.apple.documentation/documentation/uikit/uiview/2891013-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 ``ImageAnalysisInteraction/preferredInteractionTypes`` property. To recognize all types of content, specify the ``ImageAnalysisInteraction/InteractionTypes/automatic`` option, or choose a combination of types by assigning an array: ```swift interaction.preferredInteractionTypes = [.textSelection, .imageSubject] ``` To begin interaction, call one of the ``ImageAnalyzer`` class's `analyze` methods, such as ``ImageAnalyzer/analyze(_:configuration:)`` and set the result onto this class's ``ImageAnalysisOverlayView/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 ``ImageAnalysisInteraction/delegate`` property. If your image view isn't an instance of <doc://com.apple.documentation/documentation/uikit/uiimageview>, your app needs to define the interactive area within the image by implementing the ``ImageAnalysisInteractionDelegate/contentsRect(for:)-187x`` method.

Members (43)

method · iOS 16.0+

didMove

TypeScript
didMove(view?: (_UIKit_UIView) | null): Promise<void>
Swift declaration
@MainActor @preconcurrency final func didMove(to view: UIView?)

Performs an action after the view adds or removes the interaction from its interaction array. - Parameter view: The view that owns and contains the interaction in its interaction array.

init · iOS 16.0+

init

TypeScript
static init(): Promise<ImageAnalysisInteraction>
Swift declaration
@MainActor override dynamic init()

Creates an interaction for Live Text actions with items in an image.

method · iOS 16.0+

willMove

TypeScript
willMove(view?: (_UIKit_UIView) | null): Promise<void>
Swift declaration
@MainActor @preconcurrency final func willMove(to view: UIView?)

Performs an action before the view adds or removes the interaction from its interaction array. - Parameter view: The view that owns and contains the interaction in its interaction array.

get · iOS 16.0+

view

TypeScript
get view(): Promise<(_UIKit_UIView) | null>
Swift declaration
@MainActor @preconcurrency weak final var view: UIView? { get }

The view that uses this interaction.

get · iOS 16.0+

activeInteractionTypes

TypeScript
get activeInteractionTypes(): Promise<ImageAnalysisInteraction_InteractionTypes>
Swift declaration
@MainActor final var activeInteractionTypes: ImageAnalysisInteraction.InteractionTypes { get }

The types of interactions that a person actively performs. This property is always a concrete type that’s never set to ``ImageAnalysisInteraction/InteractionTypes/automatic``.

get · iOS 16.0+

preferredInteractionTypes

TypeScript
get preferredInteractionTypes(): Promise<ImageAnalysisInteraction_InteractionTypes>
Swift declaration
@MainActor final var preferredInteractionTypes: ImageAnalysisInteraction.InteractionTypes { get set }

The types of interactions that people can perform with the image. You need to set this property to enable interactions with the image. If this property contains ``ImageAnalysisInteraction/InteractionTypes/automatic``, the interaction ignores the other types in the set. The default value for this property is an empty array that disables any interactions. If you set this property to one or more types, the interaction sets the view’s <doc://com.apple.documentation/documentation/uikit/uiview/1622577-isuserinteractionenabled> property to `true` so that the interaction begins. For example, when you’re ready to start the Live Text interface, set this property to ``ImageAnalysisInteraction/InteractionTypes/automatic``. If you set this property to an empty array, the image analysis interaction doesn’t reset the view’s `isUserInteractionEnabled` property to `false`.

set · iOS 16.0+

preferredInteractionTypes

TypeScript
setPreferredInteractionTypes(value: ImageAnalysisInteraction_InteractionTypes): Promise<void>
Swift declaration
@MainActor final var preferredInteractionTypes: ImageAnalysisInteraction.InteractionTypes { get set }

The types of interactions that people can perform with the image. You need to set this property to enable interactions with the image. If this property contains ``ImageAnalysisInteraction/InteractionTypes/automatic``, the interaction ignores the other types in the set. The default value for this property is an empty array that disables any interactions. If you set this property to one or more types, the interaction sets the view’s <doc://com.apple.documentation/documentation/uikit/uiview/1622577-isuserinteractionenabled> property to `true` so that the interaction begins. For example, when you’re ready to start the Live Text interface, set this property to ``ImageAnalysisInteraction/InteractionTypes/automatic``. If you set this property to an empty array, the image analysis interaction doesn’t reset the view’s `isUserInteractionEnabled` property to `false`.

get · iOS 16.0+

contentsRect

TypeScript
get contentsRect(): Promise<{ x: number; y: number; width: number; height: number }>
Swift declaration
@MainActor final var contentsRect: CGRect { get }

A rectangle, in unit coordinate space, that describes the content area of the interaction. If the interaction’s view isn't an instance of <doc://com.apple.documentation/documentation/uikit/uiimageview>, your app sets the value for this property by implementing the ``VisionKit/ImageAnalysisInteractionDelegate`` callback ``VisionKit/ImageAnalysisInteractionDelegate/contentsRect(for:)-187x``. The default return value is the unit rectangle, `[0.0, 0.0, 1.0, 1.0]`, which represents the whole view contents.

get · iOS 17.0+

selectedText

TypeScript
get selectedText(): Promise<string>
Swift declaration
@MainActor final var selectedText: String { get }

The current selected text.

get · iOS 17.0+

selectedRanges

TypeScript
get selectedRanges(): Promise<Array<SDKHandle>>
Swift declaration
@MainActor final var selectedRanges: [Range<String.Index>] { get set }

Sets selected text ranges.

set · iOS 17.0+

selectedRanges

TypeScript
setSelectedRanges(value: Array<SDKHandle>): Promise<void>
Swift declaration
@MainActor final var selectedRanges: [Range<String.Index>] { get set }

Sets selected text ranges.

method · iOS 16.0+

analysisHasText

TypeScript
analysisHasText(point: { x: number; y: number }): Promise<boolean>
Swift declaration
@MainActor final func analysisHasText(at point: CGPoint) -> Bool

Returns a Boolean value that indicates whether the analysis finds text at the specified point. - Parameter point: A point in the image, in view coordinates. - Returns: `true` if text exists at `point`; otherwise, `false`.

method · iOS 16.0+

hasDataDetector

TypeScript
hasDataDetector(point: { x: number; y: number }): Promise<boolean>
Swift declaration
@MainActor final func hasDataDetector(at point: CGPoint) -> Bool

Returns a Boolean value that indicates whether the analysis detects data at the specified point. - Parameter point: A point in the image, in view coordinates. - Returns: `true` if the analyzer detects data at `point`; otherwise, `false`.

method · iOS 16.0+

hasInteractiveItem

TypeScript
hasInteractiveItem(point: { x: number; y: number }): Promise<boolean>
Swift declaration
@MainActor final func hasInteractiveItem(at point: CGPoint) -> Bool

Returns a Boolean value that indicates whether active text, data detectors, or supplementary interface objects exist at the specified point. - Parameter point: A point in the image, in view coordinates. - Returns: `true` if active text, data detectors, or supplementary interface objects exist at `point`; otherwise, `false`.

method · iOS 16.0+

resetTextSelection

TypeScript
resetTextSelection(): Promise<void>
Swift declaration
@MainActor final func resetTextSelection()

Removes a person’s text selection from the interface.

get · iOS 16.0+

highlightedSubjects

TypeScript
get highlightedSubjects(): Promise<Array<ImageAnalysisInteraction_Subject>>
Swift declaration
@MainActor final var highlightedSubjects: Set<ImageAnalysisInteraction.Subject> { get set }

All highlighted subjects in the interaction image.

set · iOS 16.0+

highlightedSubjects

TypeScript
setHighlightedSubjects(value: Array<ImageAnalysisInteraction_Subject>): Promise<void>
Swift declaration
@MainActor final var highlightedSubjects: Set<ImageAnalysisInteraction.Subject> { get set }

All highlighted subjects in the interaction image.

get · iOS 16.0+

liveTextButtonVisible

TypeScript
get liveTextButtonVisible(): Promise<boolean>
Swift declaration
@MainActor final var liveTextButtonVisible: Bool { get }

A Boolean value that indicates whether the Live Text button appears. When a person taps the Live Text button, it highlights recognized items in the image.

get · iOS 16.0+

hasActiveTextSelection

TypeScript
get hasActiveTextSelection(): Promise<boolean>
Swift declaration
@MainActor final var hasActiveTextSelection: Bool { get }

A Boolean value that indicates whether a person or the app has text selected within the image. If ``VisionKit/ImageAnalysisInteraction/InteractionTypes/textSelection`` is an active interaction type, a person can select text using a standard input method and the app can select text through the ``selectedRanges`` property. If neither a person nor the app select any text, then this property returns `false`.

get · iOS 17.0+

selectedAttributedText

TypeScript
get selectedAttributedText(): Promise<_Foundation_AttributedString>
Swift declaration
@MainActor final var selectedAttributedText: AttributedString { get }

The current selected attributed text.

method · iOS 16.0+

hasSupplementaryInterface

TypeScript
hasSupplementaryInterface(point: { x: number; y: number }): Promise<boolean>
Swift declaration
@MainActor final func hasSupplementaryInterface(at point: CGPoint) -> Bool

Returns a Boolean value that indicates whether supplementary interface objects exist at the specified point. Supplementary interface objects include the Live Text button and Quick Actions, depending on the item type. - Parameter point: A point in the image, in view coordinates. - Returns: `true` if supplementary interface objects exist at `point`; otherwise, `false`.

get · iOS 16.0+

selectableItemsHighlighted

TypeScript
get selectableItemsHighlighted(): Promise<boolean>
Swift declaration
@MainActor final var selectableItemsHighlighted: Bool { get set }

A Boolean value that indicates whether the interaction highlights actionable text or data the analyzer detects in text. The interaction object manages this property value for you. It sets this property to `false` if you set the ``ImageAnalysisInteraction/analysis`` property or the ``ImageAnalysisInteraction/activeInteractionTypes`` property to an empty set. Otherwise, it sets this property depending on whether a person toggles the Live Text button in the interface.

set · iOS 16.0+

selectableItemsHighlighted

TypeScript
setSelectableItemsHighlighted(value: boolean): Promise<void>
Swift declaration
@MainActor final var selectableItemsHighlighted: Bool { get set }

A Boolean value that indicates whether the interaction highlights actionable text or data the analyzer detects in text. The interaction object manages this property value for you. It sets this property to `false` if you set the ``ImageAnalysisInteraction/analysis`` property or the ``ImageAnalysisInteraction/activeInteractionTypes`` property to an empty set. Otherwise, it sets this property depending on whether a person toggles the Live Text button in the interface.

method · iOS 16.0+

setContentsRectNeedsUpdate

TypeScript
setContentsRectNeedsUpdate(): Promise<void>
Swift declaration
@MainActor final func setContentsRectNeedsUpdate()

Informs the view that contains the image when the layout changes and the view needs to reload its content. The framework ignores calls to this method when your app adds the interaction to a <doc://com.apple.documentation/documentation/uikit/uiimageview>, which calculates the ``contentsRect`` based on the image view's <doc://com.apple.documentation/documentation/uikit/uiviewcontentmode>. When the view that contains the image isn’t an instance of <doc://com.apple.documentation/documentation/uikit/uiimageview>, call this method when the layout changes. The interaction then invokes the delegate’s ``ImageAnalysisInteractionDelegate/contentsRect(for:)-187x`` callback, which provides the updated content area to the system.

get · iOS 16.0+

supplementaryInterfaceFont

TypeScript
get supplementaryInterfaceFont(): Promise<(_UIKit_UIFont) | null>
Swift declaration
@MainActor final var supplementaryInterfaceFont: UIFont? { get set }

The font to use for the supplementary interface. The interaction also uses the font weight for image symbols, but ignores the point size to keep button sizes consistent.

set · iOS 16.0+

supplementaryInterfaceFont

TypeScript
setSupplementaryInterfaceFont(value?: (_UIKit_UIFont) | null): Promise<void>
Swift declaration
@MainActor final var supplementaryInterfaceFont: UIFont? { get set }

The font to use for the supplementary interface. The interaction also uses the font weight for image symbols, but ignores the point size to keep button sizes consistent.

get · iOS 16.0+

isSupplementaryInterfaceHidden

TypeScript
get isSupplementaryInterfaceHidden(): Promise<boolean>
Swift declaration
@MainActor final var isSupplementaryInterfaceHidden: Bool { get set }

A Boolean value that indicates whether the view hides supplementary interface objects. Supplementary interface objects include the Live Text button and Quick Actions, depending on the item type. Setting this property invokes the ``ImageAnalysisInteraction/setSupplementaryInterfaceHidden(_:animated:)`` method, passing this property value and `true` for the `animated` parameter.

set · iOS 16.0+

isSupplementaryInterfaceHidden

TypeScript
setIsSupplementaryInterfaceHidden(value: boolean): Promise<void>
Swift declaration
@MainActor final var isSupplementaryInterfaceHidden: Bool { get set }

A Boolean value that indicates whether the view hides supplementary interface objects. Supplementary interface objects include the Live Text button and Quick Actions, depending on the item type. Setting this property invokes the ``ImageAnalysisInteraction/setSupplementaryInterfaceHidden(_:animated:)`` method, passing this property value and `true` for the `animated` parameter.

method · iOS 16.0+

setSupplementaryInterfaceHidden

TypeScript
setSupplementaryInterfaceHidden(hidden: boolean, animated: boolean): Promise<void>
Swift declaration
@MainActor final func setSupplementaryInterfaceHidden(_ hidden: Bool, animated: Bool)

Hides or shows supplementary interface objects, such as the Live Action button and Quick Actions, depending on the item type. - Parameter hidden: `true` to hide the supplementary interface; otherwise, `false`. - Parameter animated: `true` to animate the interface transition; otherwise, `false`.

get · iOS 16.0+

supplementaryInterfaceContentInsets

TypeScript
get supplementaryInterfaceContentInsets(): Promise<{ top: number; left: number; bottom: number; right: number }>
Swift declaration
@MainActor final var supplementaryInterfaceContentInsets: UIEdgeInsets { get set }

The distances the edges of content are inset from the supplementary interface.

set · iOS 16.0+

supplementaryInterfaceContentInsets

TypeScript
setSupplementaryInterfaceContentInsets(value: { top: number; left: number; bottom: number; right: number }): Promise<void>
Swift declaration
@MainActor final var supplementaryInterfaceContentInsets: UIEdgeInsets { get set }

The distances the edges of content are inset from the supplementary interface.

get · iOS 16.0+

allowLongPressForDataDetectorsInTextMode

TypeScript
get allowLongPressForDataDetectorsInTextMode(): Promise<boolean>
Swift declaration
@MainActor final var allowLongPressForDataDetectorsInTextMode: Bool { get set }

A Boolean value that indicates whether people can press and hold text to activate data detectors. If you set this property to `true` when the interaction type is just text, people can press and hold data in text, even when data detectors aren’t active. Otherwise, people can perform only text actions, such as copy and translate. The default value for this property is `true`.

set · iOS 16.0+

allowLongPressForDataDetectorsInTextMode

TypeScript
setAllowLongPressForDataDetectorsInTextMode(value: boolean): Promise<void>
Swift declaration
@MainActor final var allowLongPressForDataDetectorsInTextMode: Bool { get set }

A Boolean value that indicates whether people can press and hold text to activate data detectors. If you set this property to `true` when the interaction type is just text, people can press and hold data in text, even when data detectors aren’t active. Otherwise, people can perform only text actions, such as copy and translate. The default value for this property is `true`.

get · iOS 17.0+

text

TypeScript
get text(): Promise<string>
Swift declaration
@MainActor final var text: String { get }

The text contents of the current image analysis.

method · iOS 16.0+

image

TypeScript
image(subjects: Array<ImageAnalysisInteraction_Subject>): Promise<_UIKit_UIImage>
Swift declaration
@MainActor final func image(for subjects: Set<ImageAnalysisInteraction.Subject>) async throws -> UIImage

Provides an image asynchronously that contains the given subjects with the background removed. - parameter subjects: An array of subjects to include in the image. If one or more subjects fail to produce an image, the method throws ``VisionKit/ImageAnalysisInteraction/SubjectUnavailable/imageUnavailable``.

method · iOS 16.0+

hasText

TypeScript
hasText(point: { x: number; y: number }): Promise<boolean>
Swift declaration
@MainActor final func hasText(at point: CGPoint) -> Bool

Returns a Boolean value that indicates whether active text exists at the specified point. - Parameter point: A point in the image, in view coordinates. - Returns: `true` if active text exists at `point`; otherwise, `false`.

method · iOS 16.0+

subject

TypeScript
subject(point: { x: number; y: number }): Promise<(ImageAnalysisInteraction_Subject) | null>
Swift declaration
@MainActor final func subject(at point: CGPoint) async -> ImageAnalysisInteraction.Subject?

Returns the subject at the given point within the interaction's image, if one exists. This method works for interaction types that include ``VisionKit/ImageAnalysisInteraction/InteractionTypes/imageSubject``. The following code retrieves a subject image given a screen point, for instance, where a person taps: ```swift let configuration = ImageAnalyzer.Configuration() ... interaction.preferredInteractionTypes = [.imageSubject] ... let viewPoint = /* A point in view coordinates */ if let subjectObject = try await interaction.subject(at: viewPoint) { if let image = subjectObject.image { // Do something with the subject image. } } ``` - parameter point: A point in view coordinates at which to select a subject. - returns: The subject that resides at `point`; or, `nil`, if no subject resides at `point`.

get · iOS 16.0+

analysis

TypeScript
get analysis(): Promise<(ImageAnalysis) | null>
Swift declaration
@MainActor final var analysis: ImageAnalysis? { get set }

The results of analyzing an image for items that people can interact with.

set · iOS 16.0+

analysis

TypeScript
setAnalysis(value?: (ImageAnalysis) | null): Promise<void>
Swift declaration
@MainActor final var analysis: ImageAnalysis? { get set }

The results of analyzing an image for items that people can interact with.

get · iOS 16.0+

delegate

TypeScript
get delegate(): Promise<(SDKHandle) | null>
Swift declaration
@MainActor weak final var delegate: (any ImageAnalysisInteractionDelegate)? { get set }

The delegate that handles the interaction callbacks.

set · iOS 16.0+

delegate

TypeScript
setDelegate(value?: (SDKHandle) | null): Promise<void>
Swift declaration
@MainActor weak final var delegate: (any ImageAnalysisInteractionDelegate)? { get set }

The delegate that handles the interaction callbacks.

get · iOS 16.0+

subjects

TypeScript
get subjects(): Promise<Array<ImageAnalysisInteraction_Subject>>
Swift declaration
@MainActor final var subjects: Set<ImageAnalysisInteraction.Subject> { get async }

The set of all subjects the framework identifies in an image.

init · iOS 16.0+

init

TypeScript
static init35637(delegate: SDKHandle): Promise<ImageAnalysisInteraction>
Swift declaration
@MainActor convenience init(_ delegate: any ImageAnalysisInteractionDelegate)

Creates an interaction for Live Text actions with the specified delegate. - Parameter delegate: The object that provides details about the interface for the interaction.

Skipped declarations

No declarations were skipped in this snapshot.

All VisionKit types →