├── .gitignore ├── Example ├── Example.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── xcshareddata │ │ └── xcschemes │ │ └── FaceAware.xcscheme ├── Example │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Contents.json │ │ └── sample.imageset │ │ │ ├── Contents.json │ │ │ └── girl-1252995_1280.jpg │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ └── ViewController.swift └── FaceAware │ ├── FaceAware.h │ └── Info.plist ├── FaceAware.podspec ├── FaceAware ├── Attachable.swift └── UIImageView+FaceAware.swift ├── Images ├── avatarExample.png ├── inspectable.png └── largeExample.jpg ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | ## Playgrounds 31 | timeline.xctimeline 32 | playground.xcworkspace 33 | 34 | # Swift Package Manager 35 | # 36 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 37 | # Packages/ 38 | .build/ 39 | 40 | # CocoaPods 41 | # 42 | # We recommend against adding the Pods directory to your .gitignore. However 43 | # you should judge for yourself, the pros and cons are mentioned at: 44 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 45 | # 46 | # Pods/ 47 | 48 | # Carthage 49 | # 50 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 51 | # Carthage/Checkouts 52 | 53 | Carthage/Build 54 | 55 | # fastlane 56 | # 57 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 58 | # screenshots whenever they are needed. 59 | # For more information about the recommended setup visit: 60 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 61 | 62 | fastlane/report.xml 63 | fastlane/Preview.html 64 | fastlane/screenshots 65 | fastlane/test_output 66 | .DS_Store 67 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 7DCFCEEC1D8D5B9D00FE3229 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DCFCEEB1D8D5B9D00FE3229 /* AppDelegate.swift */; }; 11 | 7DCFCEEE1D8D5B9D00FE3229 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DCFCEED1D8D5B9D00FE3229 /* ViewController.swift */; }; 12 | 7DCFCEF11D8D5B9D00FE3229 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7DCFCEEF1D8D5B9D00FE3229 /* Main.storyboard */; }; 13 | 7DCFCEF31D8D5B9D00FE3229 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7DCFCEF21D8D5B9D00FE3229 /* Assets.xcassets */; }; 14 | 7DCFCEF61D8D5B9D00FE3229 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7DCFCEF41D8D5B9D00FE3229 /* LaunchScreen.storyboard */; }; 15 | 8B477CF8215850E4000DEBD7 /* Attachable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B477CF621585087000DEBD7 /* Attachable.swift */; }; 16 | 8B7879CD20BE57B700490FAA /* UIImageView+FaceAware.swift in Headers */ = {isa = PBXBuildFile; fileRef = 7D0D35631D8D72CF00632729 /* UIImageView+FaceAware.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 17 | 8B9DECFB20BE4E82000CB1F0 /* FaceAware.h in Headers */ = {isa = PBXBuildFile; fileRef = 8B9DECF920BE4E82000CB1F0 /* FaceAware.h */; settings = {ATTRIBUTES = (Public, ); }; }; 18 | 8B9DECFE20BE4E82000CB1F0 /* FaceAware.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9DECF720BE4E82000CB1F0 /* FaceAware.framework */; }; 19 | 8B9DED0020BE4E82000CB1F0 /* FaceAware.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9DECF720BE4E82000CB1F0 /* FaceAware.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 20 | 8B9DED0420BE4E8D000CB1F0 /* UIImageView+FaceAware.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D0D35631D8D72CF00632729 /* UIImageView+FaceAware.swift */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | 8B9DECFC20BE4E82000CB1F0 /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = 7DCFCEE01D8D5B9D00FE3229 /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = 8B9DECF620BE4E82000CB1F0; 29 | remoteInfo = FaceAware; 30 | }; 31 | /* End PBXContainerItemProxy section */ 32 | 33 | /* Begin PBXCopyFilesBuildPhase section */ 34 | 8B9DECFF20BE4E82000CB1F0 /* Embed Frameworks */ = { 35 | isa = PBXCopyFilesBuildPhase; 36 | buildActionMask = 2147483647; 37 | dstPath = ""; 38 | dstSubfolderSpec = 10; 39 | files = ( 40 | 8B9DED0020BE4E82000CB1F0 /* FaceAware.framework in Embed Frameworks */, 41 | ); 42 | name = "Embed Frameworks"; 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXCopyFilesBuildPhase section */ 46 | 47 | /* Begin PBXFileReference section */ 48 | 7D0D35631D8D72CF00632729 /* UIImageView+FaceAware.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImageView+FaceAware.swift"; sourceTree = ""; }; 49 | 7DCFCEE81D8D5B9D00FE3229 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 50 | 7DCFCEEB1D8D5B9D00FE3229 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 51 | 7DCFCEED1D8D5B9D00FE3229 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 52 | 7DCFCEF01D8D5B9D00FE3229 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 53 | 7DCFCEF21D8D5B9D00FE3229 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 54 | 7DCFCEF51D8D5B9D00FE3229 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 55 | 7DCFCEF71D8D5B9D00FE3229 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 56 | 8B477CF621585087000DEBD7 /* Attachable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Attachable.swift; sourceTree = ""; }; 57 | 8B9DECF720BE4E82000CB1F0 /* FaceAware.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FaceAware.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 58 | 8B9DECF920BE4E82000CB1F0 /* FaceAware.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FaceAware.h; sourceTree = ""; }; 59 | 8B9DECFA20BE4E82000CB1F0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 60 | /* End PBXFileReference section */ 61 | 62 | /* Begin PBXFrameworksBuildPhase section */ 63 | 7DCFCEE51D8D5B9D00FE3229 /* Frameworks */ = { 64 | isa = PBXFrameworksBuildPhase; 65 | buildActionMask = 2147483647; 66 | files = ( 67 | 8B9DECFE20BE4E82000CB1F0 /* FaceAware.framework in Frameworks */, 68 | ); 69 | runOnlyForDeploymentPostprocessing = 0; 70 | }; 71 | 8B9DECF320BE4E82000CB1F0 /* Frameworks */ = { 72 | isa = PBXFrameworksBuildPhase; 73 | buildActionMask = 2147483647; 74 | files = ( 75 | ); 76 | runOnlyForDeploymentPostprocessing = 0; 77 | }; 78 | /* End PBXFrameworksBuildPhase section */ 79 | 80 | /* Begin PBXGroup section */ 81 | 7D0D35621D8D72CF00632729 /* FaceAware */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | 7D0D35631D8D72CF00632729 /* UIImageView+FaceAware.swift */, 85 | 8B477CF621585087000DEBD7 /* Attachable.swift */, 86 | ); 87 | name = FaceAware; 88 | path = ../../FaceAware; 89 | sourceTree = ""; 90 | }; 91 | 7DCFCEDF1D8D5B9D00FE3229 = { 92 | isa = PBXGroup; 93 | children = ( 94 | 7DCFCEEA1D8D5B9D00FE3229 /* Example */, 95 | 8B9DECF820BE4E82000CB1F0 /* FaceAware */, 96 | 7DCFCEE91D8D5B9D00FE3229 /* Products */, 97 | ); 98 | sourceTree = ""; 99 | }; 100 | 7DCFCEE91D8D5B9D00FE3229 /* Products */ = { 101 | isa = PBXGroup; 102 | children = ( 103 | 7DCFCEE81D8D5B9D00FE3229 /* Example.app */, 104 | 8B9DECF720BE4E82000CB1F0 /* FaceAware.framework */, 105 | ); 106 | name = Products; 107 | sourceTree = ""; 108 | }; 109 | 7DCFCEEA1D8D5B9D00FE3229 /* Example */ = { 110 | isa = PBXGroup; 111 | children = ( 112 | 7D0D35621D8D72CF00632729 /* FaceAware */, 113 | 7DCFCEEB1D8D5B9D00FE3229 /* AppDelegate.swift */, 114 | 7DCFCEED1D8D5B9D00FE3229 /* ViewController.swift */, 115 | 7DCFCEEF1D8D5B9D00FE3229 /* Main.storyboard */, 116 | 7DCFCEF21D8D5B9D00FE3229 /* Assets.xcassets */, 117 | 7DCFCEF41D8D5B9D00FE3229 /* LaunchScreen.storyboard */, 118 | 7DCFCEF71D8D5B9D00FE3229 /* Info.plist */, 119 | ); 120 | path = Example; 121 | sourceTree = ""; 122 | }; 123 | 8B9DECF820BE4E82000CB1F0 /* FaceAware */ = { 124 | isa = PBXGroup; 125 | children = ( 126 | 8B9DECF920BE4E82000CB1F0 /* FaceAware.h */, 127 | 8B9DECFA20BE4E82000CB1F0 /* Info.plist */, 128 | ); 129 | path = FaceAware; 130 | sourceTree = ""; 131 | }; 132 | /* End PBXGroup section */ 133 | 134 | /* Begin PBXHeadersBuildPhase section */ 135 | 8B9DECF420BE4E82000CB1F0 /* Headers */ = { 136 | isa = PBXHeadersBuildPhase; 137 | buildActionMask = 2147483647; 138 | files = ( 139 | 8B9DECFB20BE4E82000CB1F0 /* FaceAware.h in Headers */, 140 | 8B7879CD20BE57B700490FAA /* UIImageView+FaceAware.swift in Headers */, 141 | ); 142 | runOnlyForDeploymentPostprocessing = 0; 143 | }; 144 | /* End PBXHeadersBuildPhase section */ 145 | 146 | /* Begin PBXNativeTarget section */ 147 | 7DCFCEE71D8D5B9D00FE3229 /* Example */ = { 148 | isa = PBXNativeTarget; 149 | buildConfigurationList = 7DCFCEFA1D8D5B9D00FE3229 /* Build configuration list for PBXNativeTarget "Example" */; 150 | buildPhases = ( 151 | 7DCFCEE41D8D5B9D00FE3229 /* Sources */, 152 | 7DCFCEE51D8D5B9D00FE3229 /* Frameworks */, 153 | 7DCFCEE61D8D5B9D00FE3229 /* Resources */, 154 | 8B9DECFF20BE4E82000CB1F0 /* Embed Frameworks */, 155 | ); 156 | buildRules = ( 157 | ); 158 | dependencies = ( 159 | 8B9DECFD20BE4E82000CB1F0 /* PBXTargetDependency */, 160 | ); 161 | name = Example; 162 | productName = Example; 163 | productReference = 7DCFCEE81D8D5B9D00FE3229 /* Example.app */; 164 | productType = "com.apple.product-type.application"; 165 | }; 166 | 8B9DECF620BE4E82000CB1F0 /* FaceAware */ = { 167 | isa = PBXNativeTarget; 168 | buildConfigurationList = 8B9DED0320BE4E82000CB1F0 /* Build configuration list for PBXNativeTarget "FaceAware" */; 169 | buildPhases = ( 170 | 8B9DECF220BE4E82000CB1F0 /* Sources */, 171 | 8B9DECF320BE4E82000CB1F0 /* Frameworks */, 172 | 8B9DECF420BE4E82000CB1F0 /* Headers */, 173 | 8B9DECF520BE4E82000CB1F0 /* Resources */, 174 | ); 175 | buildRules = ( 176 | ); 177 | dependencies = ( 178 | ); 179 | name = FaceAware; 180 | productName = FaceAware; 181 | productReference = 8B9DECF720BE4E82000CB1F0 /* FaceAware.framework */; 182 | productType = "com.apple.product-type.framework"; 183 | }; 184 | /* End PBXNativeTarget section */ 185 | 186 | /* Begin PBXProject section */ 187 | 7DCFCEE01D8D5B9D00FE3229 /* Project object */ = { 188 | isa = PBXProject; 189 | attributes = { 190 | LastSwiftUpdateCheck = 0800; 191 | LastUpgradeCheck = 1020; 192 | ORGANIZATIONNAME = "Pear Pi"; 193 | TargetAttributes = { 194 | 7DCFCEE71D8D5B9D00FE3229 = { 195 | CreatedOnToolsVersion = 8.0; 196 | LastSwiftMigration = 1000; 197 | ProvisioningStyle = Automatic; 198 | }; 199 | 8B9DECF620BE4E82000CB1F0 = { 200 | CreatedOnToolsVersion = 9.4; 201 | LastSwiftMigration = 1020; 202 | ProvisioningStyle = Automatic; 203 | }; 204 | }; 205 | }; 206 | buildConfigurationList = 7DCFCEE31D8D5B9D00FE3229 /* Build configuration list for PBXProject "Example" */; 207 | compatibilityVersion = "Xcode 3.2"; 208 | developmentRegion = en; 209 | hasScannedForEncodings = 0; 210 | knownRegions = ( 211 | en, 212 | Base, 213 | ); 214 | mainGroup = 7DCFCEDF1D8D5B9D00FE3229; 215 | productRefGroup = 7DCFCEE91D8D5B9D00FE3229 /* Products */; 216 | projectDirPath = ""; 217 | projectRoot = ""; 218 | targets = ( 219 | 7DCFCEE71D8D5B9D00FE3229 /* Example */, 220 | 8B9DECF620BE4E82000CB1F0 /* FaceAware */, 221 | ); 222 | }; 223 | /* End PBXProject section */ 224 | 225 | /* Begin PBXResourcesBuildPhase section */ 226 | 7DCFCEE61D8D5B9D00FE3229 /* Resources */ = { 227 | isa = PBXResourcesBuildPhase; 228 | buildActionMask = 2147483647; 229 | files = ( 230 | 7DCFCEF61D8D5B9D00FE3229 /* LaunchScreen.storyboard in Resources */, 231 | 7DCFCEF31D8D5B9D00FE3229 /* Assets.xcassets in Resources */, 232 | 7DCFCEF11D8D5B9D00FE3229 /* Main.storyboard in Resources */, 233 | ); 234 | runOnlyForDeploymentPostprocessing = 0; 235 | }; 236 | 8B9DECF520BE4E82000CB1F0 /* Resources */ = { 237 | isa = PBXResourcesBuildPhase; 238 | buildActionMask = 2147483647; 239 | files = ( 240 | ); 241 | runOnlyForDeploymentPostprocessing = 0; 242 | }; 243 | /* End PBXResourcesBuildPhase section */ 244 | 245 | /* Begin PBXSourcesBuildPhase section */ 246 | 7DCFCEE41D8D5B9D00FE3229 /* Sources */ = { 247 | isa = PBXSourcesBuildPhase; 248 | buildActionMask = 2147483647; 249 | files = ( 250 | 7DCFCEEE1D8D5B9D00FE3229 /* ViewController.swift in Sources */, 251 | 7DCFCEEC1D8D5B9D00FE3229 /* AppDelegate.swift in Sources */, 252 | ); 253 | runOnlyForDeploymentPostprocessing = 0; 254 | }; 255 | 8B9DECF220BE4E82000CB1F0 /* Sources */ = { 256 | isa = PBXSourcesBuildPhase; 257 | buildActionMask = 2147483647; 258 | files = ( 259 | 8B477CF8215850E4000DEBD7 /* Attachable.swift in Sources */, 260 | 8B9DED0420BE4E8D000CB1F0 /* UIImageView+FaceAware.swift in Sources */, 261 | ); 262 | runOnlyForDeploymentPostprocessing = 0; 263 | }; 264 | /* End PBXSourcesBuildPhase section */ 265 | 266 | /* Begin PBXTargetDependency section */ 267 | 8B9DECFD20BE4E82000CB1F0 /* PBXTargetDependency */ = { 268 | isa = PBXTargetDependency; 269 | target = 8B9DECF620BE4E82000CB1F0 /* FaceAware */; 270 | targetProxy = 8B9DECFC20BE4E82000CB1F0 /* PBXContainerItemProxy */; 271 | }; 272 | /* End PBXTargetDependency section */ 273 | 274 | /* Begin PBXVariantGroup section */ 275 | 7DCFCEEF1D8D5B9D00FE3229 /* Main.storyboard */ = { 276 | isa = PBXVariantGroup; 277 | children = ( 278 | 7DCFCEF01D8D5B9D00FE3229 /* Base */, 279 | ); 280 | name = Main.storyboard; 281 | sourceTree = ""; 282 | }; 283 | 7DCFCEF41D8D5B9D00FE3229 /* LaunchScreen.storyboard */ = { 284 | isa = PBXVariantGroup; 285 | children = ( 286 | 7DCFCEF51D8D5B9D00FE3229 /* Base */, 287 | ); 288 | name = LaunchScreen.storyboard; 289 | sourceTree = ""; 290 | }; 291 | /* End PBXVariantGroup section */ 292 | 293 | /* Begin XCBuildConfiguration section */ 294 | 7DCFCEF81D8D5B9D00FE3229 /* Debug */ = { 295 | isa = XCBuildConfiguration; 296 | buildSettings = { 297 | ALWAYS_SEARCH_USER_PATHS = NO; 298 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 299 | CLANG_ANALYZER_NONNULL = YES; 300 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 301 | CLANG_CXX_LIBRARY = "libc++"; 302 | CLANG_ENABLE_MODULES = YES; 303 | CLANG_ENABLE_OBJC_ARC = YES; 304 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 305 | CLANG_WARN_BOOL_CONVERSION = YES; 306 | CLANG_WARN_COMMA = YES; 307 | CLANG_WARN_CONSTANT_CONVERSION = YES; 308 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 309 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 310 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 311 | CLANG_WARN_EMPTY_BODY = YES; 312 | CLANG_WARN_ENUM_CONVERSION = YES; 313 | CLANG_WARN_INFINITE_RECURSION = YES; 314 | CLANG_WARN_INT_CONVERSION = YES; 315 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 316 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 317 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 318 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 319 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 320 | CLANG_WARN_STRICT_PROTOTYPES = YES; 321 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 322 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 323 | CLANG_WARN_UNREACHABLE_CODE = YES; 324 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 325 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 326 | COPY_PHASE_STRIP = NO; 327 | DEBUG_INFORMATION_FORMAT = dwarf; 328 | ENABLE_STRICT_OBJC_MSGSEND = YES; 329 | ENABLE_TESTABILITY = YES; 330 | GCC_C_LANGUAGE_STANDARD = gnu99; 331 | GCC_DYNAMIC_NO_PIC = NO; 332 | GCC_NO_COMMON_BLOCKS = YES; 333 | GCC_OPTIMIZATION_LEVEL = 0; 334 | GCC_PREPROCESSOR_DEFINITIONS = ( 335 | "DEBUG=1", 336 | "$(inherited)", 337 | ); 338 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 339 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 340 | GCC_WARN_UNDECLARED_SELECTOR = YES; 341 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 342 | GCC_WARN_UNUSED_FUNCTION = YES; 343 | GCC_WARN_UNUSED_VARIABLE = YES; 344 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 345 | MTL_ENABLE_DEBUG_INFO = YES; 346 | ONLY_ACTIVE_ARCH = YES; 347 | SDKROOT = iphoneos; 348 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 349 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 350 | SWIFT_VERSION = 3.0; 351 | }; 352 | name = Debug; 353 | }; 354 | 7DCFCEF91D8D5B9D00FE3229 /* Release */ = { 355 | isa = XCBuildConfiguration; 356 | buildSettings = { 357 | ALWAYS_SEARCH_USER_PATHS = NO; 358 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 359 | CLANG_ANALYZER_NONNULL = YES; 360 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 361 | CLANG_CXX_LIBRARY = "libc++"; 362 | CLANG_ENABLE_MODULES = YES; 363 | CLANG_ENABLE_OBJC_ARC = YES; 364 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 365 | CLANG_WARN_BOOL_CONVERSION = YES; 366 | CLANG_WARN_COMMA = YES; 367 | CLANG_WARN_CONSTANT_CONVERSION = YES; 368 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 369 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 370 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 371 | CLANG_WARN_EMPTY_BODY = YES; 372 | CLANG_WARN_ENUM_CONVERSION = YES; 373 | CLANG_WARN_INFINITE_RECURSION = YES; 374 | CLANG_WARN_INT_CONVERSION = YES; 375 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 376 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 377 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 378 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 379 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 380 | CLANG_WARN_STRICT_PROTOTYPES = YES; 381 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 382 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 383 | CLANG_WARN_UNREACHABLE_CODE = YES; 384 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 385 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 386 | COPY_PHASE_STRIP = NO; 387 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 388 | ENABLE_NS_ASSERTIONS = NO; 389 | ENABLE_STRICT_OBJC_MSGSEND = YES; 390 | GCC_C_LANGUAGE_STANDARD = gnu99; 391 | GCC_NO_COMMON_BLOCKS = YES; 392 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 393 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 394 | GCC_WARN_UNDECLARED_SELECTOR = YES; 395 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 396 | GCC_WARN_UNUSED_FUNCTION = YES; 397 | GCC_WARN_UNUSED_VARIABLE = YES; 398 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 399 | MTL_ENABLE_DEBUG_INFO = NO; 400 | SDKROOT = iphoneos; 401 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 402 | SWIFT_VERSION = 3.0; 403 | VALIDATE_PRODUCT = YES; 404 | }; 405 | name = Release; 406 | }; 407 | 7DCFCEFB1D8D5B9D00FE3229 /* Debug */ = { 408 | isa = XCBuildConfiguration; 409 | buildSettings = { 410 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 411 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 412 | CODE_SIGN_IDENTITY = "iPhone Developer"; 413 | DEVELOPMENT_TEAM = ""; 414 | INFOPLIST_FILE = Example/Info.plist; 415 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 416 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 417 | MARKETING_VERSION = 2.1.0; 418 | PRODUCT_BUNDLE_IDENTIFIER = "beaunouvelle.faceaware-example"; 419 | PRODUCT_NAME = "$(TARGET_NAME)"; 420 | SWIFT_VERSION = 5.0; 421 | }; 422 | name = Debug; 423 | }; 424 | 7DCFCEFC1D8D5B9D00FE3229 /* Release */ = { 425 | isa = XCBuildConfiguration; 426 | buildSettings = { 427 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 428 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 429 | CODE_SIGN_IDENTITY = "iPhone Developer"; 430 | DEVELOPMENT_TEAM = ""; 431 | INFOPLIST_FILE = Example/Info.plist; 432 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 433 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 434 | MARKETING_VERSION = 2.1.0; 435 | PRODUCT_BUNDLE_IDENTIFIER = "beaunouvelle.faceaware-example"; 436 | PRODUCT_NAME = "$(TARGET_NAME)"; 437 | SWIFT_VERSION = 5.0; 438 | }; 439 | name = Release; 440 | }; 441 | 8B9DED0120BE4E82000CB1F0 /* Debug */ = { 442 | isa = XCBuildConfiguration; 443 | buildSettings = { 444 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 445 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 446 | CLANG_ENABLE_OBJC_WEAK = YES; 447 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 448 | CODE_SIGN_IDENTITY = ""; 449 | CODE_SIGN_STYLE = Automatic; 450 | CURRENT_PROJECT_VERSION = 1; 451 | DEFINES_MODULE = YES; 452 | DEVELOPMENT_TEAM = ""; 453 | DYLIB_COMPATIBILITY_VERSION = 1; 454 | DYLIB_CURRENT_VERSION = 1; 455 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 456 | GCC_C_LANGUAGE_STANDARD = gnu11; 457 | INFOPLIST_FILE = FaceAware/Info.plist; 458 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 459 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 460 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 461 | MARKETING_VERSION = 2.1.0; 462 | PRODUCT_BUNDLE_IDENTIFIER = beaunouvelle.faceaware; 463 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 464 | SKIP_INSTALL = YES; 465 | SWIFT_VERSION = 5.0; 466 | TARGETED_DEVICE_FAMILY = "1,2"; 467 | VERSIONING_SYSTEM = "apple-generic"; 468 | VERSION_INFO_PREFIX = ""; 469 | }; 470 | name = Debug; 471 | }; 472 | 8B9DED0220BE4E82000CB1F0 /* Release */ = { 473 | isa = XCBuildConfiguration; 474 | buildSettings = { 475 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 476 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 477 | CLANG_ENABLE_OBJC_WEAK = YES; 478 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 479 | CODE_SIGN_IDENTITY = ""; 480 | CODE_SIGN_STYLE = Automatic; 481 | CURRENT_PROJECT_VERSION = 1; 482 | DEFINES_MODULE = YES; 483 | DEVELOPMENT_TEAM = ""; 484 | DYLIB_COMPATIBILITY_VERSION = 1; 485 | DYLIB_CURRENT_VERSION = 1; 486 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 487 | GCC_C_LANGUAGE_STANDARD = gnu11; 488 | INFOPLIST_FILE = FaceAware/Info.plist; 489 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 490 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 491 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 492 | MARKETING_VERSION = 2.1.0; 493 | PRODUCT_BUNDLE_IDENTIFIER = beaunouvelle.faceaware; 494 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 495 | SKIP_INSTALL = YES; 496 | SWIFT_VERSION = 5.0; 497 | TARGETED_DEVICE_FAMILY = "1,2"; 498 | VERSIONING_SYSTEM = "apple-generic"; 499 | VERSION_INFO_PREFIX = ""; 500 | }; 501 | name = Release; 502 | }; 503 | /* End XCBuildConfiguration section */ 504 | 505 | /* Begin XCConfigurationList section */ 506 | 7DCFCEE31D8D5B9D00FE3229 /* Build configuration list for PBXProject "Example" */ = { 507 | isa = XCConfigurationList; 508 | buildConfigurations = ( 509 | 7DCFCEF81D8D5B9D00FE3229 /* Debug */, 510 | 7DCFCEF91D8D5B9D00FE3229 /* Release */, 511 | ); 512 | defaultConfigurationIsVisible = 0; 513 | defaultConfigurationName = Release; 514 | }; 515 | 7DCFCEFA1D8D5B9D00FE3229 /* Build configuration list for PBXNativeTarget "Example" */ = { 516 | isa = XCConfigurationList; 517 | buildConfigurations = ( 518 | 7DCFCEFB1D8D5B9D00FE3229 /* Debug */, 519 | 7DCFCEFC1D8D5B9D00FE3229 /* Release */, 520 | ); 521 | defaultConfigurationIsVisible = 0; 522 | defaultConfigurationName = Release; 523 | }; 524 | 8B9DED0320BE4E82000CB1F0 /* Build configuration list for PBXNativeTarget "FaceAware" */ = { 525 | isa = XCConfigurationList; 526 | buildConfigurations = ( 527 | 8B9DED0120BE4E82000CB1F0 /* Debug */, 528 | 8B9DED0220BE4E82000CB1F0 /* Release */, 529 | ); 530 | defaultConfigurationIsVisible = 0; 531 | defaultConfigurationName = Release; 532 | }; 533 | /* End XCConfigurationList section */ 534 | }; 535 | rootObject = 7DCFCEE01D8D5B9D00FE3229 /* Project object */; 536 | } 537 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/xcshareddata/xcschemes/FaceAware.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /Example/Example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Example 4 | // 5 | // Created by Beau Nouvelle on 17/9/16. 6 | // 7 | 8 | import UIKit 9 | 10 | @UIApplicationMain 11 | class AppDelegate: UIResponder, UIApplicationDelegate { 12 | 13 | var window: UIWindow? 14 | 15 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 16 | // Override point for customization after application launch. 17 | return true 18 | } 19 | 20 | func applicationWillResignActive(_ application: UIApplication) { 21 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 22 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 23 | } 24 | 25 | func applicationDidEnterBackground(_ application: UIApplication) { 26 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 27 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 28 | } 29 | 30 | func applicationWillEnterForeground(_ application: UIApplication) { 31 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 32 | } 33 | 34 | func applicationDidBecomeActive(_ application: UIApplication) { 35 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 36 | } 37 | 38 | func applicationWillTerminate(_ application: UIApplication) { 39 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "size" : "1024x1024", 46 | "scale" : "1x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/sample.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "girl-1252995_1280.jpg", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/sample.imageset/girl-1252995_1280.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeauNouvelle/FaceAware/4390b11505c7f346fe08faff9cd2d9d5d30fcfe2/Example/Example/Assets.xcassets/sample.imageset/girl-1252995_1280.jpg -------------------------------------------------------------------------------- /Example/Example/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Example/Example/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 44 | 50 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /Example/Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | $(MARKETING_VERSION) 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeRight 35 | UIInterfaceOrientationLandscapeLeft 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Example/Example/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Example 4 | // 5 | // Created by Beau Nouvelle on 17/9/16. 6 | // 7 | 8 | import UIKit 9 | import FaceAware 10 | 11 | class ViewController: UIViewController { 12 | 13 | @IBOutlet weak var faceAwareImageView: UIImageView! 14 | 15 | override func viewDidLoad() { 16 | super.viewDidLoad() 17 | // Do any additional setup after loading the view, typically from a nib. 18 | faceAwareImageView.didFocusOnFaces = { 19 | print("Did finish focussing") 20 | } 21 | } 22 | 23 | @IBAction func toggle(_ sender: UIButton) { 24 | faceAwareImageView.focusOnFaces = !faceAwareImageView.focusOnFaces 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Example/FaceAware/FaceAware.h: -------------------------------------------------------------------------------- 1 | // 2 | // FaceAware.h 3 | // FaceAware 4 | // 5 | // Created by Beau Nouvelle on 30/5/18. 6 | // Copyright © 2018 Pear Pi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for FaceAware. 12 | FOUNDATION_EXPORT double FaceAwareVersionNumber; 13 | 14 | //! Project version string for FaceAware. 15 | FOUNDATION_EXPORT const unsigned char FaceAwareVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /Example/FaceAware/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | $(MARKETING_VERSION) 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /FaceAware.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint FaceAware.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | 11 | s.name = "FaceAware" 12 | s.version = "2.1.0" 13 | s.summary = "A UIImageView extension that focus on faces within an image." 14 | s.swift_version = '5.1' 15 | 16 | s.description = <<-DESC 17 | An extension that gives UIImageView the ability to focus on faces within an image when using AspectFill. 18 | DESC 19 | 20 | s.homepage = "https://github.com/BeauNouvelle/FaceAware" 21 | s.screenshots = "https://raw.githubusercontent.com/BeauNouvelle/FaceAware/master/Images/avatarExample.png", "https://raw.githubusercontent.com/BeauNouvelle/FaceAware/master/Images/largeExample.jpg" 22 | 23 | s.license = { :type => "MIT", :file => "LICENSE" } 24 | s.author = "Beau Nouvelle" 25 | s.social_media_url = "http://twitter.com/BeauNouvelle" 26 | 27 | s.platform = :ios, "8.0" 28 | 29 | s.source = { :git => "https://github.com/BeauNouvelle/FaceAware.git", :tag => "#{s.version}" } 30 | 31 | s.source_files = "FaceAware/*.{swift}" 32 | s.exclude_files = "Classes/Exclude" 33 | 34 | end 35 | -------------------------------------------------------------------------------- /FaceAware/Attachable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Attachable.swift 3 | // FaceAware 4 | // 5 | // The MIT License (MIT) 6 | // 7 | // Copyright (c) 2018 Beau Nouvelle 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | 27 | import Foundation 28 | 29 | internal class ClosureWrapper { 30 | var closure: (T) -> Void 31 | init(_ closure: @escaping (T) -> Void) { 32 | self.closure = closure 33 | } 34 | } 35 | 36 | internal protocol Attachable { 37 | func set(_ attachObj: Any?, forKey key: inout UInt) 38 | func getAttach(forKey key: inout UInt) -> Any? 39 | } 40 | 41 | extension Attachable { 42 | 43 | public func set(_ attachObj: Any?, forKey key: inout UInt) { 44 | objc_setAssociatedObject(self, &key, attachObj, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 45 | } 46 | 47 | public func getAttach(forKey key: inout UInt) -> Any? { 48 | return objc_getAssociatedObject(self, &key) 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /FaceAware/UIImageView+FaceAware.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+FaceAware.swift 3 | // FaceAware 4 | // 5 | // The MIT License (MIT) 6 | // 7 | // Copyright (c) 2018 Beau Nouvelle 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | 27 | import UIKit 28 | import ObjectiveC 29 | 30 | private var closureKey: UInt = 0 31 | private var debugKey: UInt = 1 32 | 33 | @IBDesignable 34 | extension UIImageView: Attachable { 35 | 36 | @IBInspectable 37 | /// Adds a red bordered rectangle around any faces detected. 38 | public var debugFaceAware: Bool { 39 | set { 40 | set(newValue, forKey: &debugKey) 41 | } get { 42 | guard let debug = getAttach(forKey: &debugKey) as? Bool else { 43 | return false 44 | } 45 | return debug 46 | } 47 | } 48 | 49 | @IBInspectable 50 | /// Set this to true if you want to center the image on any detected faces. 51 | public var focusOnFaces: Bool { 52 | set { 53 | let image = self.image 54 | set(image: image, focusOnFaces: newValue) 55 | } get { 56 | return sublayer() != nil ? true : false 57 | } 58 | } 59 | 60 | public func set(image: UIImage?, focusOnFaces: Bool) { 61 | guard focusOnFaces == true else { 62 | self.removeImageLayer(image: image) 63 | return 64 | } 65 | setImageAndFocusOnFaces(image: image) 66 | } 67 | 68 | /// You can provide a closure here to receive a callback for when all face 69 | /// detection and image adjustments have been finished. 70 | public var didFocusOnFaces: (() -> Void)? { 71 | set { 72 | set(newValue, forKey: &closureKey) 73 | } get { 74 | return getAttach(forKey: &closureKey) as? (() -> Void) 75 | } 76 | } 77 | 78 | private func setImageAndFocusOnFaces(image: UIImage?) { 79 | DispatchQueue.global(qos: .default).async { 80 | guard let image = image else { 81 | return 82 | } 83 | 84 | guard let ciImage = CIImage(image: image) else { 85 | return 86 | } 87 | 88 | let detector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: [CIDetectorAccuracy: CIDetectorAccuracyLow]) 89 | let features = detector!.features(in: ciImage) 90 | 91 | if !features.isEmpty { 92 | if self.debugFaceAware { 93 | print("found \(features.count) faces") 94 | } 95 | let imgSize = CGSize(width: image.cgImage!.width, height: image.cgImage!.height) 96 | self.applyFaceDetection(for: features, size: imgSize, image: image) 97 | } else { 98 | if self.debugFaceAware { 99 | print("No faces found") 100 | } 101 | self.removeImageLayer(image: image) 102 | } 103 | } 104 | } 105 | 106 | private func applyFaceDetection(for features: [CIFeature], size: CGSize, image: UIImage) { 107 | var rect = features[0].bounds 108 | rect.origin.y = size.height - rect.minY - rect.height 109 | var rightBorder = Double(rect.minX + rect.width) 110 | var bottomBorder = Double(rect.minY + rect.height) 111 | 112 | for feature in features.dropFirst() { 113 | var oneRect = feature.bounds 114 | oneRect.origin.y = size.height - oneRect.minY - oneRect.height 115 | rect.origin.x = min(oneRect.minX, rect.minX) 116 | rect.origin.y = min(oneRect.minY, rect.minY) 117 | 118 | rightBorder = max(Double(oneRect.minX + oneRect.width), Double(rightBorder)) 119 | bottomBorder = max(Double(oneRect.minY + oneRect.height), Double(bottomBorder)) 120 | } 121 | 122 | rect.size.width = CGFloat(rightBorder) - rect.minX 123 | rect.size.height = CGFloat(bottomBorder) - rect.minY 124 | 125 | var offset = CGPoint.zero 126 | var finalSize = size 127 | 128 | DispatchQueue.main.async { 129 | if size.width / size.height > self.bounds.width / self.bounds.height { 130 | var centerX = rect.minX + rect.width / 2.0 131 | 132 | finalSize.height = self.bounds.height 133 | finalSize.width = size.width / size.height * finalSize.height 134 | centerX = finalSize.width / size.width * centerX 135 | 136 | offset.x = centerX - self.bounds.width * 0.5 137 | if offset.x < 0 { 138 | offset.x = 0 139 | } else if offset.x + self.bounds.width > finalSize.width { 140 | offset.x = finalSize.width - self.bounds.width 141 | } 142 | offset.x = -offset.x 143 | } else { 144 | var centerY = rect.minY + rect.height / 2.0 145 | 146 | finalSize.width = self.bounds.width 147 | finalSize.height = size.height / size.width * finalSize.width 148 | centerY = finalSize.width / size.width * centerY 149 | 150 | offset.y = centerY - self.bounds.height * CGFloat(1-0.618) 151 | if offset.y < 0 { 152 | offset.y = 0 153 | } else if offset.y + self.bounds.height > finalSize.height { 154 | finalSize.height = self.bounds.height 155 | offset.y = finalSize.height 156 | } 157 | offset.y = -offset.y 158 | } 159 | } 160 | 161 | let newImage: UIImage 162 | if self.debugFaceAware { 163 | newImage = drawDebugRectangles(from: image, size: size, features: features) 164 | } else { 165 | newImage = image 166 | } 167 | 168 | DispatchQueue.main.sync { 169 | self.image = newImage 170 | 171 | let layer = self.imageLayer() 172 | layer.contents = newImage.cgImage 173 | layer.frame = CGRect(origin: offset, size: finalSize) 174 | self.didFocusOnFaces?() 175 | } 176 | } 177 | 178 | private func drawDebugRectangles(from image: UIImage, size: CGSize, features: [CIFeature]) -> UIImage { 179 | // Draw rectangles around detected faces 180 | let rawImage = UIImage(cgImage: image.cgImage!) 181 | UIGraphicsBeginImageContext(size) 182 | rawImage.draw(at: .zero) 183 | 184 | let context = UIGraphicsGetCurrentContext() 185 | context?.setStrokeColor(UIColor.red.cgColor) 186 | context?.setLineWidth(3) 187 | 188 | features.forEach({ 189 | var faceViewBounds = $0.bounds 190 | faceViewBounds.origin.y = size.height - faceViewBounds.minY - faceViewBounds.height 191 | 192 | context?.addRect(faceViewBounds) 193 | context?.drawPath(using: .stroke) 194 | }) 195 | 196 | let newImage = UIGraphicsGetImageFromCurrentImageContext()! 197 | UIGraphicsEndImageContext() 198 | return newImage 199 | } 200 | 201 | private func imageLayer() -> CALayer { 202 | if let layer = sublayer() { 203 | return layer 204 | } 205 | 206 | let subLayer = CALayer() 207 | subLayer.name = "AspectFillFaceAware" 208 | subLayer.actions = ["contents": NSNull(), "bounds": NSNull(), "position": NSNull()] 209 | layer.addSublayer(subLayer) 210 | return subLayer 211 | } 212 | 213 | private func removeImageLayer(image: UIImage?) { 214 | DispatchQueue.main.async { 215 | // avoid redundant layer when focus on faces for the image of cell specified in UITableView 216 | self.imageLayer().removeFromSuperlayer() 217 | self.image = image 218 | } 219 | } 220 | 221 | private func sublayer() -> CALayer? { 222 | return layer.sublayers?.first { $0.name == "AspectFillFaceAware" } 223 | } 224 | 225 | override open func layoutSubviews() { 226 | super.layoutSubviews() 227 | if focusOnFaces { 228 | setImageAndFocusOnFaces(image: self.image) 229 | } 230 | } 231 | 232 | } 233 | -------------------------------------------------------------------------------- /Images/avatarExample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeauNouvelle/FaceAware/4390b11505c7f346fe08faff9cd2d9d5d30fcfe2/Images/avatarExample.png -------------------------------------------------------------------------------- /Images/inspectable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeauNouvelle/FaceAware/4390b11505c7f346fe08faff9cd2d9d5d30fcfe2/Images/inspectable.png -------------------------------------------------------------------------------- /Images/largeExample.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeauNouvelle/FaceAware/4390b11505c7f346fe08faff9cd2d9d5d30fcfe2/Images/largeExample.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Beau Nouvelle 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FaceAware 2 | 3 | 4 | 5 | Sometimes the aspect ratios of images we need to work with don't quite fit within the confines of our UIImageViews. 6 | 7 | In most cases we can use AspectFill to fit the image to the bounds of a UIImageView without stretching or leaving whitespace, however when it comes to photos of people, it's quite often to have the faces cropped out if they're not perfectly centered. 8 | 9 | This is where FaceAware comes in. 10 | It will analyse an image either through `UIImageView`'s `image` property, or one you set using one of the built in functions and focus in on any faces it can find within. 11 | 12 | The most common use for FaceAware is with avatars. 13 | 14 | With FaceAware your users will no longer have to crop and adjust their profile pictures. 15 | 16 | 17 | 18 | Based on these two older projects: 19 | 20 | * [BetterFace-Swift](https://github.com/croath/UIImageView-BetterFace-Swift) 21 | * [FaceAwareFill](https://github.com/Julioacarrettoni/UIImageView_FaceAwareFill) 22 | 23 | Both of which don't seem to be maintained anymore. 24 | 25 | ## Requirements ## 26 | * Swift 5.1 27 | * iOS 8.0+ 28 | * Xcode 11 29 | 30 | ## Installation ## 31 | #### Manual #### 32 | Simply drag `UIImageView+FaceAware.swift` into your project. 33 | 34 | #### Carthage #### 35 | - Add `github "BeauNouvelle/FaceAware"` to your `Cartfile` 36 | 37 | More information on installing and setting up Carthage can be found here: 38 | https://github.com/Carthage/Carthage 39 | 40 | #### Cocoapods #### 41 | - Add `pod 'FaceAware'` to your pod file. 42 | - Add `import FaceAware` to the top of your files where you wish to use it. 43 | 44 | ## Usage ## 45 | There are a few ways to get your image views focussing in on faces within images. 46 | 47 | #### Interface Builder #### 48 | This is the easiest method and doesn't require writing any code. 49 | The extension makes use of `@IBDesignable` and `@IBInspectable` so you can turn on focusOnFaces from within IB. However you won't actually see the extension working until you run your project. 50 | 51 | 52 | 53 | #### Code #### 54 | You can set `focusOnFaces` to `true`. 55 | 56 | ```swift 57 | someImageView.focusOnFaces = true 58 | ``` 59 | Be sure to set this *after* setting your image. If no image is present when this is called, there will be no faces to focus on. 60 | 61 | ------ 62 | 63 | Alternatively you can use: 64 | 65 | ```swift 66 | someImageView.set(image: myImage, focusOnFaces: true) 67 | ``` 68 | Which elimates the worry of not having an image previously set. 69 | 70 | ------ 71 | 72 | You can also recieve a callback for when face detection and any image adjustments have been completed by passing in a closure to the `didFocusOnFaces` property. 73 | 74 | ```swift 75 | someImageView.didFocusOnFaces = { 76 | print("Did finish focussing") 77 | } 78 | ``` 79 | 80 | #### Debugging #### 81 | FaceAware now features a debug mode which draws red squares around any detected faces within an image. To enable you can set the `debug` property to true. 82 | 83 | ```swift 84 | someImageView.debug = true 85 | ``` 86 | 87 | You can also set this flag within interface builder. 88 | 89 | 90 | ## More help? Questions? ## 91 | Reach out to me on Twitter [@beaunouvelle](https://twitter.com/BeauNouvelle) 92 | Also, if you're using this in your project and you like it, please let me know so I can continue working on it! 93 | 94 | ## Future Plans ## 95 | - [ ] Add an option to only focus on largest/closest face in photo. 96 | --------------------------------------------------------------------------------