├── LiveTextWithImage.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcuserdata │ └── runhuahuang.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── LiveTextWithImage ├── Assets.xcassets │ ├── 1.imageset │ │ ├── Contents.json │ │ └── IMG_3946.PNG │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── ContentView.swift ├── LiveTextInteraction.swift ├── LiveTextInteractionView.swift ├── LiveTextWithImageApp.swift └── Preview Content │ └── Preview Assets.xcassets │ └── Contents.json ├── README.md └── intro.jpg /LiveTextWithImage.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 56; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | BDD13230285217CA00C69619 /* LiveTextWithImageApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDD1322F285217CA00C69619 /* LiveTextWithImageApp.swift */; }; 11 | BDD13232285217CA00C69619 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDD13231285217CA00C69619 /* ContentView.swift */; }; 12 | BDD13234285217CA00C69619 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BDD13233285217CA00C69619 /* Assets.xcassets */; }; 13 | BDD13237285217CA00C69619 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BDD13236285217CA00C69619 /* Preview Assets.xcassets */; }; 14 | BDD1323E28521D7000C69619 /* LiveTextInteraction.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDD1323D28521D7000C69619 /* LiveTextInteraction.swift */; }; 15 | BDD1324028521E6200C69619 /* LiveTextInteractionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDD1323F28521E6200C69619 /* LiveTextInteractionView.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | BDD1322C285217CA00C69619 /* LiveTextWithImage.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LiveTextWithImage.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | BDD1322F285217CA00C69619 /* LiveTextWithImageApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveTextWithImageApp.swift; sourceTree = ""; }; 21 | BDD13231285217CA00C69619 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 22 | BDD13233285217CA00C69619 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 23 | BDD13236285217CA00C69619 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 24 | BDD1323D28521D7000C69619 /* LiveTextInteraction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveTextInteraction.swift; sourceTree = ""; }; 25 | BDD1323F28521E6200C69619 /* LiveTextInteractionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveTextInteractionView.swift; sourceTree = ""; }; 26 | /* End PBXFileReference section */ 27 | 28 | /* Begin PBXFrameworksBuildPhase section */ 29 | BDD13229285217CA00C69619 /* Frameworks */ = { 30 | isa = PBXFrameworksBuildPhase; 31 | buildActionMask = 2147483647; 32 | files = ( 33 | ); 34 | runOnlyForDeploymentPostprocessing = 0; 35 | }; 36 | /* End PBXFrameworksBuildPhase section */ 37 | 38 | /* Begin PBXGroup section */ 39 | BDD13223285217C900C69619 = { 40 | isa = PBXGroup; 41 | children = ( 42 | BDD1322E285217CA00C69619 /* LiveTextWithImage */, 43 | BDD1322D285217CA00C69619 /* Products */, 44 | ); 45 | sourceTree = ""; 46 | }; 47 | BDD1322D285217CA00C69619 /* Products */ = { 48 | isa = PBXGroup; 49 | children = ( 50 | BDD1322C285217CA00C69619 /* LiveTextWithImage.app */, 51 | ); 52 | name = Products; 53 | sourceTree = ""; 54 | }; 55 | BDD1322E285217CA00C69619 /* LiveTextWithImage */ = { 56 | isa = PBXGroup; 57 | children = ( 58 | BDD1322F285217CA00C69619 /* LiveTextWithImageApp.swift */, 59 | BDD13231285217CA00C69619 /* ContentView.swift */, 60 | BDD1323F28521E6200C69619 /* LiveTextInteractionView.swift */, 61 | BDD1323D28521D7000C69619 /* LiveTextInteraction.swift */, 62 | BDD13233285217CA00C69619 /* Assets.xcassets */, 63 | BDD13235285217CA00C69619 /* Preview Content */, 64 | ); 65 | path = LiveTextWithImage; 66 | sourceTree = ""; 67 | }; 68 | BDD13235285217CA00C69619 /* Preview Content */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | BDD13236285217CA00C69619 /* Preview Assets.xcassets */, 72 | ); 73 | path = "Preview Content"; 74 | sourceTree = ""; 75 | }; 76 | /* End PBXGroup section */ 77 | 78 | /* Begin PBXNativeTarget section */ 79 | BDD1322B285217CA00C69619 /* LiveTextWithImage */ = { 80 | isa = PBXNativeTarget; 81 | buildConfigurationList = BDD1323A285217CA00C69619 /* Build configuration list for PBXNativeTarget "LiveTextWithImage" */; 82 | buildPhases = ( 83 | BDD13228285217CA00C69619 /* Sources */, 84 | BDD13229285217CA00C69619 /* Frameworks */, 85 | BDD1322A285217CA00C69619 /* Resources */, 86 | ); 87 | buildRules = ( 88 | ); 89 | dependencies = ( 90 | ); 91 | name = LiveTextWithImage; 92 | productName = LiveTextWithImage; 93 | productReference = BDD1322C285217CA00C69619 /* LiveTextWithImage.app */; 94 | productType = "com.apple.product-type.application"; 95 | }; 96 | /* End PBXNativeTarget section */ 97 | 98 | /* Begin PBXProject section */ 99 | BDD13224285217C900C69619 /* Project object */ = { 100 | isa = PBXProject; 101 | attributes = { 102 | BuildIndependentTargetsInParallel = 1; 103 | LastSwiftUpdateCheck = 1400; 104 | LastUpgradeCheck = 1400; 105 | TargetAttributes = { 106 | BDD1322B285217CA00C69619 = { 107 | CreatedOnToolsVersion = 14.0; 108 | }; 109 | }; 110 | }; 111 | buildConfigurationList = BDD13227285217C900C69619 /* Build configuration list for PBXProject "LiveTextWithImage" */; 112 | compatibilityVersion = "Xcode 14.0"; 113 | developmentRegion = en; 114 | hasScannedForEncodings = 0; 115 | knownRegions = ( 116 | en, 117 | Base, 118 | ); 119 | mainGroup = BDD13223285217C900C69619; 120 | productRefGroup = BDD1322D285217CA00C69619 /* Products */; 121 | projectDirPath = ""; 122 | projectRoot = ""; 123 | targets = ( 124 | BDD1322B285217CA00C69619 /* LiveTextWithImage */, 125 | ); 126 | }; 127 | /* End PBXProject section */ 128 | 129 | /* Begin PBXResourcesBuildPhase section */ 130 | BDD1322A285217CA00C69619 /* Resources */ = { 131 | isa = PBXResourcesBuildPhase; 132 | buildActionMask = 2147483647; 133 | files = ( 134 | BDD13237285217CA00C69619 /* Preview Assets.xcassets in Resources */, 135 | BDD13234285217CA00C69619 /* Assets.xcassets in Resources */, 136 | ); 137 | runOnlyForDeploymentPostprocessing = 0; 138 | }; 139 | /* End PBXResourcesBuildPhase section */ 140 | 141 | /* Begin PBXSourcesBuildPhase section */ 142 | BDD13228285217CA00C69619 /* Sources */ = { 143 | isa = PBXSourcesBuildPhase; 144 | buildActionMask = 2147483647; 145 | files = ( 146 | BDD1324028521E6200C69619 /* LiveTextInteractionView.swift in Sources */, 147 | BDD13232285217CA00C69619 /* ContentView.swift in Sources */, 148 | BDD13230285217CA00C69619 /* LiveTextWithImageApp.swift in Sources */, 149 | BDD1323E28521D7000C69619 /* LiveTextInteraction.swift in Sources */, 150 | ); 151 | runOnlyForDeploymentPostprocessing = 0; 152 | }; 153 | /* End PBXSourcesBuildPhase section */ 154 | 155 | /* Begin XCBuildConfiguration section */ 156 | BDD13238285217CA00C69619 /* Debug */ = { 157 | isa = XCBuildConfiguration; 158 | buildSettings = { 159 | ALWAYS_SEARCH_USER_PATHS = NO; 160 | CLANG_ANALYZER_NONNULL = YES; 161 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 162 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 163 | CLANG_ENABLE_MODULES = YES; 164 | CLANG_ENABLE_OBJC_ARC = YES; 165 | CLANG_ENABLE_OBJC_WEAK = YES; 166 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 167 | CLANG_WARN_BOOL_CONVERSION = YES; 168 | CLANG_WARN_COMMA = YES; 169 | CLANG_WARN_CONSTANT_CONVERSION = YES; 170 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 171 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 172 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 173 | CLANG_WARN_EMPTY_BODY = YES; 174 | CLANG_WARN_ENUM_CONVERSION = YES; 175 | CLANG_WARN_INFINITE_RECURSION = YES; 176 | CLANG_WARN_INT_CONVERSION = YES; 177 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 178 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 179 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 180 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 181 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 182 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 183 | CLANG_WARN_STRICT_PROTOTYPES = YES; 184 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 185 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 186 | CLANG_WARN_UNREACHABLE_CODE = YES; 187 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 188 | COPY_PHASE_STRIP = NO; 189 | DEBUG_INFORMATION_FORMAT = dwarf; 190 | ENABLE_STRICT_OBJC_MSGSEND = YES; 191 | ENABLE_TESTABILITY = YES; 192 | GCC_C_LANGUAGE_STANDARD = gnu11; 193 | GCC_DYNAMIC_NO_PIC = NO; 194 | GCC_NO_COMMON_BLOCKS = YES; 195 | GCC_OPTIMIZATION_LEVEL = 0; 196 | GCC_PREPROCESSOR_DEFINITIONS = ( 197 | "DEBUG=1", 198 | "$(inherited)", 199 | ); 200 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 201 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 202 | GCC_WARN_UNDECLARED_SELECTOR = YES; 203 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 204 | GCC_WARN_UNUSED_FUNCTION = YES; 205 | GCC_WARN_UNUSED_VARIABLE = YES; 206 | IPHONEOS_DEPLOYMENT_TARGET = 16.0; 207 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 208 | MTL_FAST_MATH = YES; 209 | ONLY_ACTIVE_ARCH = YES; 210 | SDKROOT = iphoneos; 211 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 212 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 213 | }; 214 | name = Debug; 215 | }; 216 | BDD13239285217CA00C69619 /* Release */ = { 217 | isa = XCBuildConfiguration; 218 | buildSettings = { 219 | ALWAYS_SEARCH_USER_PATHS = NO; 220 | CLANG_ANALYZER_NONNULL = YES; 221 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 222 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 223 | CLANG_ENABLE_MODULES = YES; 224 | CLANG_ENABLE_OBJC_ARC = YES; 225 | CLANG_ENABLE_OBJC_WEAK = YES; 226 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 227 | CLANG_WARN_BOOL_CONVERSION = YES; 228 | CLANG_WARN_COMMA = YES; 229 | CLANG_WARN_CONSTANT_CONVERSION = YES; 230 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 231 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 232 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 233 | CLANG_WARN_EMPTY_BODY = YES; 234 | CLANG_WARN_ENUM_CONVERSION = YES; 235 | CLANG_WARN_INFINITE_RECURSION = YES; 236 | CLANG_WARN_INT_CONVERSION = YES; 237 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 238 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 239 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 240 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 241 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 242 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 243 | CLANG_WARN_STRICT_PROTOTYPES = YES; 244 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 245 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 246 | CLANG_WARN_UNREACHABLE_CODE = YES; 247 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 248 | COPY_PHASE_STRIP = NO; 249 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 250 | ENABLE_NS_ASSERTIONS = NO; 251 | ENABLE_STRICT_OBJC_MSGSEND = YES; 252 | GCC_C_LANGUAGE_STANDARD = gnu11; 253 | GCC_NO_COMMON_BLOCKS = YES; 254 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 255 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 256 | GCC_WARN_UNDECLARED_SELECTOR = YES; 257 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 258 | GCC_WARN_UNUSED_FUNCTION = YES; 259 | GCC_WARN_UNUSED_VARIABLE = YES; 260 | IPHONEOS_DEPLOYMENT_TARGET = 16.0; 261 | MTL_ENABLE_DEBUG_INFO = NO; 262 | MTL_FAST_MATH = YES; 263 | SDKROOT = iphoneos; 264 | SWIFT_COMPILATION_MODE = wholemodule; 265 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 266 | VALIDATE_PRODUCT = YES; 267 | }; 268 | name = Release; 269 | }; 270 | BDD1323B285217CA00C69619 /* Debug */ = { 271 | isa = XCBuildConfiguration; 272 | buildSettings = { 273 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 274 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 275 | CODE_SIGN_STYLE = Automatic; 276 | CURRENT_PROJECT_VERSION = 1; 277 | DEVELOPMENT_ASSET_PATHS = "\"LiveTextWithImage/Preview Content\""; 278 | DEVELOPMENT_TEAM = YRB62S584T; 279 | ENABLE_PREVIEWS = YES; 280 | GENERATE_INFOPLIST_FILE = YES; 281 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 282 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 283 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 284 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 285 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 286 | LD_RUNPATH_SEARCH_PATHS = ( 287 | "$(inherited)", 288 | "@executable_path/Frameworks", 289 | ); 290 | MARKETING_VERSION = 1.0; 291 | PRODUCT_BUNDLE_IDENTIFIER = "com.noreply-email.LiveTextWithImage"; 292 | PRODUCT_NAME = "$(TARGET_NAME)"; 293 | SWIFT_EMIT_LOC_STRINGS = YES; 294 | SWIFT_VERSION = 5.0; 295 | TARGETED_DEVICE_FAMILY = "1,2"; 296 | }; 297 | name = Debug; 298 | }; 299 | BDD1323C285217CA00C69619 /* Release */ = { 300 | isa = XCBuildConfiguration; 301 | buildSettings = { 302 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 303 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 304 | CODE_SIGN_STYLE = Automatic; 305 | CURRENT_PROJECT_VERSION = 1; 306 | DEVELOPMENT_ASSET_PATHS = "\"LiveTextWithImage/Preview Content\""; 307 | DEVELOPMENT_TEAM = YRB62S584T; 308 | ENABLE_PREVIEWS = YES; 309 | GENERATE_INFOPLIST_FILE = YES; 310 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 311 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 312 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 313 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 314 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 315 | LD_RUNPATH_SEARCH_PATHS = ( 316 | "$(inherited)", 317 | "@executable_path/Frameworks", 318 | ); 319 | MARKETING_VERSION = 1.0; 320 | PRODUCT_BUNDLE_IDENTIFIER = "com.noreply-email.LiveTextWithImage"; 321 | PRODUCT_NAME = "$(TARGET_NAME)"; 322 | SWIFT_EMIT_LOC_STRINGS = YES; 323 | SWIFT_VERSION = 5.0; 324 | TARGETED_DEVICE_FAMILY = "1,2"; 325 | }; 326 | name = Release; 327 | }; 328 | /* End XCBuildConfiguration section */ 329 | 330 | /* Begin XCConfigurationList section */ 331 | BDD13227285217C900C69619 /* Build configuration list for PBXProject "LiveTextWithImage" */ = { 332 | isa = XCConfigurationList; 333 | buildConfigurations = ( 334 | BDD13238285217CA00C69619 /* Debug */, 335 | BDD13239285217CA00C69619 /* Release */, 336 | ); 337 | defaultConfigurationIsVisible = 0; 338 | defaultConfigurationName = Release; 339 | }; 340 | BDD1323A285217CA00C69619 /* Build configuration list for PBXNativeTarget "LiveTextWithImage" */ = { 341 | isa = XCConfigurationList; 342 | buildConfigurations = ( 343 | BDD1323B285217CA00C69619 /* Debug */, 344 | BDD1323C285217CA00C69619 /* Release */, 345 | ); 346 | defaultConfigurationIsVisible = 0; 347 | defaultConfigurationName = Release; 348 | }; 349 | /* End XCConfigurationList section */ 350 | }; 351 | rootObject = BDD13224285217C900C69619 /* Project object */; 352 | } 353 | -------------------------------------------------------------------------------- /LiveTextWithImage.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LiveTextWithImage.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /LiveTextWithImage.xcodeproj/xcuserdata/runhuahuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | LiveTextWithImage.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /LiveTextWithImage/Assets.xcassets/1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "IMG_3946.png", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /LiveTextWithImage/Assets.xcassets/1.imageset/IMG_3946.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HuangRunHua/LiveTextWithImage/ac125b968742d305129aadb299c145581cb2e306/LiveTextWithImage/Assets.xcassets/1.imageset/IMG_3946.PNG -------------------------------------------------------------------------------- /LiveTextWithImage/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /LiveTextWithImage/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "platform" : "ios", 6 | "size" : "1024x1024" 7 | } 8 | ], 9 | "info" : { 10 | "author" : "xcode", 11 | "version" : 1 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /LiveTextWithImage/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /LiveTextWithImage/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // LiveTextWithImage 4 | // 5 | // Created by Runhua Huang on 2022/6/9. 6 | // 7 | 8 | import SwiftUI 9 | import VisionKit 10 | 11 | struct ContentView: View { 12 | @State private var deviceSupportLiveText = false 13 | @State private var showDeviceNotCapacityAlert = false 14 | @State private var showLiveTextView = false 15 | var body: some View { 16 | Button { 17 | if deviceSupportLiveText { 18 | self.showLiveTextView = true 19 | } else { 20 | self.showDeviceNotCapacityAlert = true 21 | } 22 | } label: { 23 | Text("Pick an Image") 24 | .foregroundColor(.white) 25 | .padding() 26 | .frame(width: 300, height: 50) 27 | .background(Color.blue) 28 | .cornerRadius(10) 29 | } 30 | .alert("Live Text Unavailable", isPresented: $showDeviceNotCapacityAlert, actions: {}) 31 | .sheet(isPresented: $showLiveTextView, content: { 32 | LiveTextInteractionView() 33 | }) 34 | .onAppear { 35 | self.deviceSupportLiveText = ImageAnalyzer.isSupported 36 | } 37 | } 38 | } 39 | 40 | struct ContentView_Previews: PreviewProvider { 41 | static var previews: some View { 42 | ContentView() 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /LiveTextWithImage/LiveTextInteraction.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LiveTextInteraction.swift 3 | // LiveTextWithImage 4 | // 5 | // Created by Runhua Huang on 2022/6/9. 6 | 7 | 8 | import UIKit 9 | import SwiftUI 10 | import VisionKit 11 | 12 | @MainActor 13 | struct LiveTextInteraction: UIViewRepresentable { 14 | 15 | var imageName: String 16 | let imageView = LiveTextImageView() 17 | let analyzer = ImageAnalyzer() 18 | let interaction = ImageAnalysisInteraction() 19 | 20 | func makeUIView(context: Context) -> some UIView { 21 | imageView.image = UIImage(named: imageName) 22 | 23 | imageView.addInteraction(interaction) 24 | imageView.contentMode = .scaleAspectFit 25 | return imageView 26 | } 27 | 28 | func updateUIView(_ uiView: UIViewType, context: Context) { 29 | Task { 30 | let configuration = ImageAnalyzer.Configuration([.text]) 31 | do { 32 | if let image = imageView.image { 33 | let analysis = try await analyzer.analyze(image, configuration: configuration) 34 | if let analysis = analysis { 35 | interaction.analysis = analysis; 36 | interaction.preferredInteractionTypes = .textSelection 37 | } 38 | } 39 | } 40 | catch { 41 | // Handle error… 42 | } 43 | } 44 | } 45 | } 46 | 47 | class LiveTextImageView: UIImageView { 48 | // Use intrinsicContentSize to change the default image size 49 | // so that we can change the size in our SwiftUI View 50 | override var intrinsicContentSize: CGSize { 51 | .zero 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /LiveTextWithImage/LiveTextInteractionView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LiveTextInteractionView.swift 3 | // LiveTextWithImage 4 | // 5 | // Created by Runhua Huang on 2022/6/9. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct LiveTextInteractionView: View { 11 | @Environment(\.presentationMode) var presentationMode 12 | var body: some View { 13 | NavigationView { 14 | LiveTextInteraction(imageName: "1") 15 | .toolbar { 16 | ToolbarItem(placement: .navigationBarLeading) { 17 | Button { 18 | self.presentationMode.wrappedValue.dismiss() 19 | } label: { 20 | Text("Cancel") 21 | } 22 | } 23 | } 24 | .interactiveDismissDisabled(true) 25 | } 26 | } 27 | } 28 | 29 | struct LiveTextInteractionView_Previews: PreviewProvider { 30 | static var previews: some View { 31 | LiveTextInteractionView() 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LiveTextWithImage/LiveTextWithImageApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LiveTextWithImageApp.swift 3 | // LiveTextWithImage 4 | // 5 | // Created by Runhua Huang on 2022/6/9. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @main 11 | struct LiveTextWithImageApp: App { 12 | var body: some Scene { 13 | WindowGroup { 14 | ContentView() 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /LiveTextWithImage/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Live Text With Image 2 | [WWDC22: Enabling Live Text interactions with images in SwiftUI](https://developer.apple.com/documentation/visionkit/enabling_live_text_interactions_with_images) 3 | ![](https://github.com/HuangRunHua/LiveTextWithImage/raw/main/intro.jpg) 4 | -------------------------------------------------------------------------------- /intro.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HuangRunHua/LiveTextWithImage/ac125b968742d305129aadb299c145581cb2e306/intro.jpg --------------------------------------------------------------------------------