├── Example ├── ShimmerView.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── Guillian.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── Guillian.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── ShimmerView │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ └── img.imageset │ │ ├── Capture d’écran 2019-07-23 à 10.53.28.png │ │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── CollectionViewController.swift │ ├── Info.plist │ ├── ShimmerView │ ├── ShimmerAnimation.swift │ ├── ShimmerOptions.swift │ ├── UICollectionView+Shimmer.swift │ ├── UITableView+Shimmer.swift │ └── UIView+Shimmer.swift │ ├── TableViewController.swift │ └── ViewController.swift ├── LICENSE ├── README.md ├── ShimmerView ├── ShimmerAnimation.swift ├── ShimmerOptions.swift ├── UICollectionView+Shimmer.swift ├── UITableView+Shimmer.swift └── UIView+Shimmer.swift └── example_images ├── activate_shimmer.png ├── activate_shimmer_IB.png ├── classic_shimmer.gif ├── classic_shimmer_color.gif ├── classic_shimmer_color_no_border.gif ├── fade_shimmer.gif └── tableview_shimmer_classic.gif /Example/ShimmerView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | E90E817A22E6EACB00ADE56E /* UITableView+Shimmer.swift in Sources */ = {isa = PBXBuildFile; fileRef = E90E817922E6EACB00ADE56E /* UITableView+Shimmer.swift */; }; 11 | E90E817C22E6EC4E00ADE56E /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E90E817B22E6EC4E00ADE56E /* TableViewController.swift */; }; 12 | E90E818022E748E700ADE56E /* UICollectionView+Shimmer.swift in Sources */ = {isa = PBXBuildFile; fileRef = E90E817F22E748E700ADE56E /* UICollectionView+Shimmer.swift */; }; 13 | E90E818222E74A7300ADE56E /* CollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E90E818122E74A7300ADE56E /* CollectionViewController.swift */; }; 14 | E90E818422EAEE2900ADE56E /* ShimmerOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E90E818322EAEE2900ADE56E /* ShimmerOptions.swift */; }; 15 | E90E818A22EEE12500ADE56E /* ShimmerAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = E90E818922EEE12500ADE56E /* ShimmerAnimation.swift */; }; 16 | E93C969122C0F1F600050814 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E93C969022C0F1F600050814 /* AppDelegate.swift */; }; 17 | E93C969322C0F1F600050814 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E93C969222C0F1F600050814 /* ViewController.swift */; }; 18 | E93C969622C0F1F600050814 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E93C969422C0F1F600050814 /* Main.storyboard */; }; 19 | E93C969822C0F1FB00050814 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E93C969722C0F1FB00050814 /* Assets.xcassets */; }; 20 | E93C969B22C0F1FB00050814 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E93C969922C0F1FB00050814 /* LaunchScreen.storyboard */; }; 21 | E93C96A422C0F2CB00050814 /* UIView+Shimmer.swift in Sources */ = {isa = PBXBuildFile; fileRef = E93C96A322C0F2CB00050814 /* UIView+Shimmer.swift */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXFileReference section */ 25 | E90E817922E6EACB00ADE56E /* UITableView+Shimmer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITableView+Shimmer.swift"; sourceTree = ""; }; 26 | E90E817B22E6EC4E00ADE56E /* TableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = ""; }; 27 | E90E817F22E748E700ADE56E /* UICollectionView+Shimmer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UICollectionView+Shimmer.swift"; sourceTree = ""; }; 28 | E90E818122E74A7300ADE56E /* CollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionViewController.swift; sourceTree = ""; }; 29 | E90E818322EAEE2900ADE56E /* ShimmerOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShimmerOptions.swift; sourceTree = ""; }; 30 | E90E818922EEE12500ADE56E /* ShimmerAnimation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShimmerAnimation.swift; sourceTree = ""; }; 31 | E93C968D22C0F1F500050814 /* ShimmerView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ShimmerView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 32 | E93C969022C0F1F600050814 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 33 | E93C969222C0F1F600050814 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 34 | E93C969522C0F1F600050814 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 35 | E93C969722C0F1FB00050814 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 36 | E93C969A22C0F1FB00050814 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 37 | E93C969C22C0F1FB00050814 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 38 | E93C96A322C0F2CB00050814 /* UIView+Shimmer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Shimmer.swift"; sourceTree = ""; }; 39 | /* End PBXFileReference section */ 40 | 41 | /* Begin PBXFrameworksBuildPhase section */ 42 | E93C968A22C0F1F500050814 /* Frameworks */ = { 43 | isa = PBXFrameworksBuildPhase; 44 | buildActionMask = 2147483647; 45 | files = ( 46 | ); 47 | runOnlyForDeploymentPostprocessing = 0; 48 | }; 49 | /* End PBXFrameworksBuildPhase section */ 50 | 51 | /* Begin PBXGroup section */ 52 | E93C968422C0F1F500050814 = { 53 | isa = PBXGroup; 54 | children = ( 55 | E93C968F22C0F1F600050814 /* ShimmerView */, 56 | E93C968E22C0F1F500050814 /* Products */, 57 | ); 58 | sourceTree = ""; 59 | }; 60 | E93C968E22C0F1F500050814 /* Products */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | E93C968D22C0F1F500050814 /* ShimmerView.app */, 64 | ); 65 | name = Products; 66 | sourceTree = ""; 67 | }; 68 | E93C968F22C0F1F600050814 /* ShimmerView */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | E93C96A222C0F2B200050814 /* ShimmerView */, 72 | E93C969022C0F1F600050814 /* AppDelegate.swift */, 73 | E93C969222C0F1F600050814 /* ViewController.swift */, 74 | E90E817B22E6EC4E00ADE56E /* TableViewController.swift */, 75 | E90E818122E74A7300ADE56E /* CollectionViewController.swift */, 76 | E93C969422C0F1F600050814 /* Main.storyboard */, 77 | E93C969722C0F1FB00050814 /* Assets.xcassets */, 78 | E93C969922C0F1FB00050814 /* LaunchScreen.storyboard */, 79 | E93C969C22C0F1FB00050814 /* Info.plist */, 80 | ); 81 | path = ShimmerView; 82 | sourceTree = ""; 83 | }; 84 | E93C96A222C0F2B200050814 /* ShimmerView */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | E93C96A322C0F2CB00050814 /* UIView+Shimmer.swift */, 88 | E90E817922E6EACB00ADE56E /* UITableView+Shimmer.swift */, 89 | E90E817F22E748E700ADE56E /* UICollectionView+Shimmer.swift */, 90 | E90E818322EAEE2900ADE56E /* ShimmerOptions.swift */, 91 | E90E818922EEE12500ADE56E /* ShimmerAnimation.swift */, 92 | ); 93 | path = ShimmerView; 94 | sourceTree = ""; 95 | }; 96 | /* End PBXGroup section */ 97 | 98 | /* Begin PBXNativeTarget section */ 99 | E93C968C22C0F1F500050814 /* ShimmerView */ = { 100 | isa = PBXNativeTarget; 101 | buildConfigurationList = E93C969F22C0F1FB00050814 /* Build configuration list for PBXNativeTarget "ShimmerView" */; 102 | buildPhases = ( 103 | E93C968922C0F1F500050814 /* Sources */, 104 | E93C968A22C0F1F500050814 /* Frameworks */, 105 | E93C968B22C0F1F500050814 /* Resources */, 106 | ); 107 | buildRules = ( 108 | ); 109 | dependencies = ( 110 | ); 111 | name = ShimmerView; 112 | productName = ShimmerView; 113 | productReference = E93C968D22C0F1F500050814 /* ShimmerView.app */; 114 | productType = "com.apple.product-type.application"; 115 | }; 116 | /* End PBXNativeTarget section */ 117 | 118 | /* Begin PBXProject section */ 119 | E93C968522C0F1F500050814 /* Project object */ = { 120 | isa = PBXProject; 121 | attributes = { 122 | LastSwiftUpdateCheck = 1020; 123 | LastUpgradeCheck = 1020; 124 | ORGANIZATIONNAME = VersusMind; 125 | TargetAttributes = { 126 | E93C968C22C0F1F500050814 = { 127 | CreatedOnToolsVersion = 10.2.1; 128 | }; 129 | }; 130 | }; 131 | buildConfigurationList = E93C968822C0F1F500050814 /* Build configuration list for PBXProject "ShimmerView" */; 132 | compatibilityVersion = "Xcode 9.3"; 133 | developmentRegion = en; 134 | hasScannedForEncodings = 0; 135 | knownRegions = ( 136 | en, 137 | Base, 138 | ); 139 | mainGroup = E93C968422C0F1F500050814; 140 | productRefGroup = E93C968E22C0F1F500050814 /* Products */; 141 | projectDirPath = ""; 142 | projectRoot = ""; 143 | targets = ( 144 | E93C968C22C0F1F500050814 /* ShimmerView */, 145 | ); 146 | }; 147 | /* End PBXProject section */ 148 | 149 | /* Begin PBXResourcesBuildPhase section */ 150 | E93C968B22C0F1F500050814 /* Resources */ = { 151 | isa = PBXResourcesBuildPhase; 152 | buildActionMask = 2147483647; 153 | files = ( 154 | E93C969B22C0F1FB00050814 /* LaunchScreen.storyboard in Resources */, 155 | E93C969822C0F1FB00050814 /* Assets.xcassets in Resources */, 156 | E93C969622C0F1F600050814 /* Main.storyboard in Resources */, 157 | ); 158 | runOnlyForDeploymentPostprocessing = 0; 159 | }; 160 | /* End PBXResourcesBuildPhase section */ 161 | 162 | /* Begin PBXSourcesBuildPhase section */ 163 | E93C968922C0F1F500050814 /* Sources */ = { 164 | isa = PBXSourcesBuildPhase; 165 | buildActionMask = 2147483647; 166 | files = ( 167 | E93C969322C0F1F600050814 /* ViewController.swift in Sources */, 168 | E90E817A22E6EACB00ADE56E /* UITableView+Shimmer.swift in Sources */, 169 | E93C969122C0F1F600050814 /* AppDelegate.swift in Sources */, 170 | E90E818022E748E700ADE56E /* UICollectionView+Shimmer.swift in Sources */, 171 | E90E818222E74A7300ADE56E /* CollectionViewController.swift in Sources */, 172 | E90E817C22E6EC4E00ADE56E /* TableViewController.swift in Sources */, 173 | E90E818A22EEE12500ADE56E /* ShimmerAnimation.swift in Sources */, 174 | E93C96A422C0F2CB00050814 /* UIView+Shimmer.swift in Sources */, 175 | E90E818422EAEE2900ADE56E /* ShimmerOptions.swift in Sources */, 176 | ); 177 | runOnlyForDeploymentPostprocessing = 0; 178 | }; 179 | /* End PBXSourcesBuildPhase section */ 180 | 181 | /* Begin PBXVariantGroup section */ 182 | E93C969422C0F1F600050814 /* Main.storyboard */ = { 183 | isa = PBXVariantGroup; 184 | children = ( 185 | E93C969522C0F1F600050814 /* Base */, 186 | ); 187 | name = Main.storyboard; 188 | sourceTree = ""; 189 | }; 190 | E93C969922C0F1FB00050814 /* LaunchScreen.storyboard */ = { 191 | isa = PBXVariantGroup; 192 | children = ( 193 | E93C969A22C0F1FB00050814 /* Base */, 194 | ); 195 | name = LaunchScreen.storyboard; 196 | sourceTree = ""; 197 | }; 198 | /* End PBXVariantGroup section */ 199 | 200 | /* Begin XCBuildConfiguration section */ 201 | E93C969D22C0F1FB00050814 /* Debug */ = { 202 | isa = XCBuildConfiguration; 203 | buildSettings = { 204 | ALWAYS_SEARCH_USER_PATHS = NO; 205 | CLANG_ANALYZER_NONNULL = YES; 206 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 207 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 208 | CLANG_CXX_LIBRARY = "libc++"; 209 | CLANG_ENABLE_MODULES = YES; 210 | CLANG_ENABLE_OBJC_ARC = YES; 211 | CLANG_ENABLE_OBJC_WEAK = YES; 212 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 213 | CLANG_WARN_BOOL_CONVERSION = YES; 214 | CLANG_WARN_COMMA = YES; 215 | CLANG_WARN_CONSTANT_CONVERSION = YES; 216 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 217 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 218 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 219 | CLANG_WARN_EMPTY_BODY = YES; 220 | CLANG_WARN_ENUM_CONVERSION = YES; 221 | CLANG_WARN_INFINITE_RECURSION = YES; 222 | CLANG_WARN_INT_CONVERSION = YES; 223 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 224 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 225 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 226 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 227 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 228 | CLANG_WARN_STRICT_PROTOTYPES = YES; 229 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 230 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 231 | CLANG_WARN_UNREACHABLE_CODE = YES; 232 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 233 | CODE_SIGN_IDENTITY = "iPhone Developer"; 234 | COPY_PHASE_STRIP = NO; 235 | DEBUG_INFORMATION_FORMAT = dwarf; 236 | ENABLE_STRICT_OBJC_MSGSEND = YES; 237 | ENABLE_TESTABILITY = YES; 238 | GCC_C_LANGUAGE_STANDARD = gnu11; 239 | GCC_DYNAMIC_NO_PIC = NO; 240 | GCC_NO_COMMON_BLOCKS = YES; 241 | GCC_OPTIMIZATION_LEVEL = 0; 242 | GCC_PREPROCESSOR_DEFINITIONS = ( 243 | "DEBUG=1", 244 | "$(inherited)", 245 | ); 246 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 247 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 248 | GCC_WARN_UNDECLARED_SELECTOR = YES; 249 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 250 | GCC_WARN_UNUSED_FUNCTION = YES; 251 | GCC_WARN_UNUSED_VARIABLE = YES; 252 | IPHONEOS_DEPLOYMENT_TARGET = 12.2; 253 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 254 | MTL_FAST_MATH = YES; 255 | ONLY_ACTIVE_ARCH = YES; 256 | SDKROOT = iphoneos; 257 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 258 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 259 | }; 260 | name = Debug; 261 | }; 262 | E93C969E22C0F1FB00050814 /* Release */ = { 263 | isa = XCBuildConfiguration; 264 | buildSettings = { 265 | ALWAYS_SEARCH_USER_PATHS = NO; 266 | CLANG_ANALYZER_NONNULL = YES; 267 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 268 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 269 | CLANG_CXX_LIBRARY = "libc++"; 270 | CLANG_ENABLE_MODULES = YES; 271 | CLANG_ENABLE_OBJC_ARC = YES; 272 | CLANG_ENABLE_OBJC_WEAK = YES; 273 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 274 | CLANG_WARN_BOOL_CONVERSION = YES; 275 | CLANG_WARN_COMMA = YES; 276 | CLANG_WARN_CONSTANT_CONVERSION = YES; 277 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 278 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 279 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 280 | CLANG_WARN_EMPTY_BODY = YES; 281 | CLANG_WARN_ENUM_CONVERSION = YES; 282 | CLANG_WARN_INFINITE_RECURSION = YES; 283 | CLANG_WARN_INT_CONVERSION = YES; 284 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 285 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 286 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 287 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 288 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 289 | CLANG_WARN_STRICT_PROTOTYPES = YES; 290 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 291 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 292 | CLANG_WARN_UNREACHABLE_CODE = YES; 293 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 294 | CODE_SIGN_IDENTITY = "iPhone Developer"; 295 | COPY_PHASE_STRIP = NO; 296 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 297 | ENABLE_NS_ASSERTIONS = NO; 298 | ENABLE_STRICT_OBJC_MSGSEND = YES; 299 | GCC_C_LANGUAGE_STANDARD = gnu11; 300 | GCC_NO_COMMON_BLOCKS = YES; 301 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 302 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 303 | GCC_WARN_UNDECLARED_SELECTOR = YES; 304 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 305 | GCC_WARN_UNUSED_FUNCTION = YES; 306 | GCC_WARN_UNUSED_VARIABLE = YES; 307 | IPHONEOS_DEPLOYMENT_TARGET = 12.2; 308 | MTL_ENABLE_DEBUG_INFO = NO; 309 | MTL_FAST_MATH = YES; 310 | SDKROOT = iphoneos; 311 | SWIFT_COMPILATION_MODE = wholemodule; 312 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 313 | VALIDATE_PRODUCT = YES; 314 | }; 315 | name = Release; 316 | }; 317 | E93C96A022C0F1FB00050814 /* Debug */ = { 318 | isa = XCBuildConfiguration; 319 | buildSettings = { 320 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 321 | CODE_SIGN_STYLE = Automatic; 322 | DEVELOPMENT_TEAM = FH7J82UUZR; 323 | INFOPLIST_FILE = ShimmerView/Info.plist; 324 | LD_RUNPATH_SEARCH_PATHS = ( 325 | "$(inherited)", 326 | "@executable_path/Frameworks", 327 | ); 328 | PRODUCT_BUNDLE_IDENTIFIER = com.versusmind.ShimmerView; 329 | PRODUCT_NAME = "$(TARGET_NAME)"; 330 | SWIFT_VERSION = 5.0; 331 | TARGETED_DEVICE_FAMILY = "1,2"; 332 | }; 333 | name = Debug; 334 | }; 335 | E93C96A122C0F1FB00050814 /* Release */ = { 336 | isa = XCBuildConfiguration; 337 | buildSettings = { 338 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 339 | CODE_SIGN_STYLE = Automatic; 340 | DEVELOPMENT_TEAM = FH7J82UUZR; 341 | INFOPLIST_FILE = ShimmerView/Info.plist; 342 | LD_RUNPATH_SEARCH_PATHS = ( 343 | "$(inherited)", 344 | "@executable_path/Frameworks", 345 | ); 346 | PRODUCT_BUNDLE_IDENTIFIER = com.versusmind.ShimmerView; 347 | PRODUCT_NAME = "$(TARGET_NAME)"; 348 | SWIFT_VERSION = 5.0; 349 | TARGETED_DEVICE_FAMILY = "1,2"; 350 | }; 351 | name = Release; 352 | }; 353 | /* End XCBuildConfiguration section */ 354 | 355 | /* Begin XCConfigurationList section */ 356 | E93C968822C0F1F500050814 /* Build configuration list for PBXProject "ShimmerView" */ = { 357 | isa = XCConfigurationList; 358 | buildConfigurations = ( 359 | E93C969D22C0F1FB00050814 /* Debug */, 360 | E93C969E22C0F1FB00050814 /* Release */, 361 | ); 362 | defaultConfigurationIsVisible = 0; 363 | defaultConfigurationName = Release; 364 | }; 365 | E93C969F22C0F1FB00050814 /* Build configuration list for PBXNativeTarget "ShimmerView" */ = { 366 | isa = XCConfigurationList; 367 | buildConfigurations = ( 368 | E93C96A022C0F1FB00050814 /* Debug */, 369 | E93C96A122C0F1FB00050814 /* Release */, 370 | ); 371 | defaultConfigurationIsVisible = 0; 372 | defaultConfigurationName = Release; 373 | }; 374 | /* End XCConfigurationList section */ 375 | }; 376 | rootObject = E93C968522C0F1F500050814 /* Project object */; 377 | } 378 | -------------------------------------------------------------------------------- /Example/ShimmerView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/ShimmerView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/ShimmerView.xcodeproj/project.xcworkspace/xcuserdata/Guillian.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeBzul/SimpleShimmer/25dd66fde477d26e70c77b5f5b63d35116c94b15/Example/ShimmerView.xcodeproj/project.xcworkspace/xcuserdata/Guillian.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Example/ShimmerView.xcodeproj/xcuserdata/Guillian.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Example/ShimmerView.xcodeproj/xcuserdata/Guillian.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ShimmerView.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Example/ShimmerView/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // ShimmerView 4 | // 5 | // Created by Drouin on 24/06/2019. 6 | // Copyright © 2019 VersusMind. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | // Override point for customization after application launch. 18 | return true 19 | } 20 | 21 | func applicationWillResignActive(_ application: UIApplication) { 22 | // 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. 23 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 24 | } 25 | 26 | func applicationDidEnterBackground(_ application: UIApplication) { 27 | // 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. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | func applicationWillEnterForeground(_ application: UIApplication) { 32 | // 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. 33 | } 34 | 35 | func applicationDidBecomeActive(_ application: UIApplication) { 36 | // 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. 37 | } 38 | 39 | func applicationWillTerminate(_ application: UIApplication) { 40 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 41 | } 42 | 43 | 44 | } 45 | 46 | -------------------------------------------------------------------------------- /Example/ShimmerView/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" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /Example/ShimmerView/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Example/ShimmerView/Assets.xcassets/img.imageset/Capture d’écran 2019-07-23 à 10.53.28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeBzul/SimpleShimmer/25dd66fde477d26e70c77b5f5b63d35116c94b15/Example/ShimmerView/Assets.xcassets/img.imageset/Capture d’écran 2019-07-23 à 10.53.28.png -------------------------------------------------------------------------------- /Example/ShimmerView/Assets.xcassets/img.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "Capture d’écran 2019-07-23 à 10.53.28.png" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | }, 12 | "properties" : { 13 | "template-rendering-intent" : "original" 14 | } 15 | } -------------------------------------------------------------------------------- /Example/ShimmerView/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 | -------------------------------------------------------------------------------- /Example/ShimmerView/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 | 39 | 40 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 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 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 128 | 138 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | -------------------------------------------------------------------------------- /Example/ShimmerView/CollectionViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CollectionViewController.swift 3 | // ShimmerView 4 | // 5 | // Created by Drouin on 23/07/2019. 6 | // Copyright © 2019 VersusMind. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class CollectionViewController: UIViewController { 12 | @IBOutlet var collectionView: UICollectionView! 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | collectionView.dataSource = self 16 | collectionView.delegate = self 17 | } 18 | 19 | override func viewWillAppear(_ animated: Bool) { 20 | super.viewWillAppear(animated) 21 | self.collectionView.startShimmerAnimation(withIdentifier: "collectionShimmerCell", numberOfRows: 25, numberOfSections: 1) 22 | } 23 | 24 | override func viewDidAppear(_ animated: Bool) { 25 | super.viewDidAppear(animated) 26 | 27 | DispatchQueue.main.asyncAfter(deadline: .now() + 5.0, execute: { 28 | self.collectionView.stopShimmerAnimation(animated: true) 29 | }) 30 | } 31 | } 32 | 33 | extension CollectionViewController: UICollectionViewDataSource, UICollectionViewDelegate { 34 | 35 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 36 | return 2 37 | } 38 | 39 | func numberOfSections(in collectionView: UICollectionView) -> Int { 40 | return 2 41 | } 42 | 43 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 44 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionShimmerCell", for: indexPath) 45 | return cell 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Example/ShimmerView/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 | APPL 17 | CFBundleShortVersionString 18 | 1.0 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 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Example/ShimmerView/ShimmerView/ShimmerAnimation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ShimmerAnimation.swift 3 | // ShimmerView 4 | // 5 | // Created by Drouin on 29/07/2019. 6 | // Copyright © 2019 VersusMind. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ShimmerAnimation { 12 | 13 | static func buildAnimation(view: UIView, type: ShimmerOptions.AnimationType) { 14 | switch type { 15 | case .classic: buildClassicAnimation(view: view) 16 | case .fade: buildFadeAnimation(view: view) 17 | } 18 | } 19 | 20 | static private func buildFadeAnimation(view: UIView) { 21 | let animation = CABasicAnimation(keyPath: "opacity") 22 | animation.fromValue = 0.9 23 | animation.toValue = 0.3 24 | let realDuration = ShimmerOptions.instance.animationAutoReserse ? (ShimmerOptions.instance.animationDuration * 2) : ShimmerOptions.instance.animationDuration 25 | animation.duration = CFTimeInterval(realDuration + ShimmerOptions.instance.animationDelay) 26 | animation.repeatCount = HUGE 27 | animation.autoreverses = ShimmerOptions.instance.animationAutoReserse 28 | 29 | animation.fillMode = CAMediaTimingFillMode.forwards 30 | animation.isRemovedOnCompletion = false 31 | animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut) 32 | view.layer.add(animation, forKey: "fade") 33 | } 34 | 35 | static private func buildClassicAnimation(view: UIView) { 36 | 37 | let animation = CABasicAnimation(keyPath: "transform.translation.x") 38 | animation.duration = CFTimeInterval(ShimmerOptions.instance.animationDuration) 39 | 40 | var fromValue: CGFloat = 0 41 | var toValue: CGFloat = 0 42 | switch ShimmerOptions.instance.animationDirection { 43 | case .topBottom: 44 | animation.keyPath = "transform.translation.y" 45 | fromValue = -view.frame.size.height 46 | toValue = view.frame.size.height 47 | case .bottomTop: 48 | animation.keyPath = "transform.translation.y" 49 | fromValue = view.frame.size.height 50 | toValue = -view.frame.size.height 51 | case .leftRight: 52 | fromValue = -view.frame.size.width 53 | toValue = view.frame.size.width 54 | case .rightLeft: 55 | fromValue = view.frame.size.width 56 | toValue = -view.frame.size.width 57 | } 58 | 59 | animation.fromValue = fromValue 60 | animation.toValue = toValue 61 | animation.fillMode = CAMediaTimingFillMode.forwards 62 | animation.isRemovedOnCompletion = false 63 | animation.autoreverses = ShimmerOptions.instance.animationAutoReserse 64 | 65 | let group = CAAnimationGroup() 66 | group.animations = [animation] 67 | let realDuration = ShimmerOptions.instance.animationAutoReserse ? (ShimmerOptions.instance.animationDuration * 2) : ShimmerOptions.instance.animationDuration 68 | group.duration = CFTimeInterval(realDuration + ShimmerOptions.instance.animationDelay) 69 | group.repeatCount = HUGE 70 | 71 | let gradientLayer = CAGradientLayer() 72 | gradientLayer.colors = [UIColor.clear.cgColor, UIColor.white.cgColor, UIColor.clear.cgColor] 73 | gradientLayer.frame = view.bounds 74 | 75 | switch ShimmerOptions.instance.animationDirection { 76 | case .topBottom, .bottomTop: 77 | gradientLayer.startPoint = CGPoint(x: 1.0, y: 1.0) 78 | gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.0) 79 | case .leftRight, .rightLeft: 80 | gradientLayer.startPoint = CGPoint(x: 1.0, y: 1.0) 81 | gradientLayer.endPoint = CGPoint(x: 0.0, y: 1.0) 82 | } 83 | 84 | gradientLayer.add(group, forKey: "animationShimmerView") 85 | view.layer.mask = gradientLayer 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Example/ShimmerView/ShimmerView/ShimmerOptions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwimmerOptions.swift 3 | // ShimmerView 4 | // 5 | // Created by Drouin on 26/07/2019. 6 | // Copyright © 2019 VersusMind. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public class ShimmerOptions { 12 | public static let instance = ShimmerOptions() 13 | 14 | enum Direction { 15 | case topBottom 16 | case bottomTop 17 | case leftRight 18 | case rightLeft 19 | } 20 | 21 | enum AnimationType { 22 | case classic 23 | case fade 24 | } 25 | 26 | // Animation option 27 | var animationDuration: CGFloat = 1.0 28 | var animationDelay: CGFloat = 0.3 29 | var animationAutoReserse = true 30 | var animationDirection: Direction = .leftRight 31 | var animationType: AnimationType = .classic 32 | 33 | // Shimmer background option 34 | var gradientColor = UIColor.gray 35 | var borderWidth: CGFloat = 0.0 36 | var borderColor = UIColor.gray 37 | var backgroundColor = UIColor.white 38 | 39 | private init() { } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /Example/ShimmerView/ShimmerView/UICollectionView+Shimmer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UICollectionView+Shimmer.swift 3 | // ShimmerView 4 | // 5 | // Created by Drouin on 23/07/2019. 6 | // Copyright © 2019 VersusMind. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | private var _collectionViewShimmerAssociateObjectValue: Int = 2 12 | 13 | 14 | // Accessible Method 15 | extension UICollectionView { 16 | func startShimmerAnimation(withIdentifier: String, numberOfRows: Int? = 2, numberOfSections: Int? = 2) { 17 | // Activate Swizzle method ! 18 | UICollectionView.Swizzle() 19 | 20 | addCollectionViewKey(key: self.hash) 21 | collectionViewShimmer?.numberOfRows = numberOfRows ?? 2 22 | collectionViewShimmer?.numberOfSections = numberOfSections ?? 2 23 | collectionViewShimmer?.identifierCell = withIdentifier 24 | collectionViewShimmer?.delegateBeforeShimmer = self.delegate 25 | collectionViewShimmer?.dataSourceBeforeShimmer = self.dataSource 26 | 27 | self.dataSource = collectionViewShimmer 28 | self.delegate = collectionViewShimmer 29 | self.reloadData() 30 | } 31 | 32 | override func stopShimmerAnimation(animated: Bool = true) { 33 | removeCollectionViewKey(key: self.hash) 34 | if animated { 35 | UIView.transition(with: self, 36 | duration: 0.35, 37 | options: .transitionCrossDissolve, 38 | animations: { 39 | self.endShimmerReloadData() 40 | }) 41 | } else { 42 | endShimmerReloadData() 43 | } 44 | } 45 | } 46 | 47 | //UICollectionView Internal gestion method 48 | extension UICollectionView { 49 | private func endShimmerReloadData() { 50 | self.dataSource = self.collectionViewShimmer?.dataSourceBeforeShimmer 51 | self.delegate = self.collectionViewShimmer?.delegateBeforeShimmer 52 | self.reloadData() 53 | } 54 | 55 | private func addCollectionViewKey(key: Int) { 56 | var findedKey = false 57 | if let collectionViewShimmer = collectionViewShimmer { 58 | for oldKey in collectionViewShimmer.shimmerStartedKey where oldKey == key { 59 | findedKey = true 60 | } 61 | 62 | if !findedKey { 63 | collectionViewShimmer.shimmerStartedKey.append(key) 64 | } 65 | } 66 | } 67 | 68 | private func removeCollectionViewKey(key: Int) { 69 | if let collectionViewShimmer = collectionViewShimmer { 70 | for (index, oldKey) in collectionViewShimmer.shimmerStartedKey.enumerated() where oldKey == key { 71 | collectionViewShimmer.shimmerStartedKey.remove(at: index) 72 | } 73 | } 74 | } 75 | } 76 | 77 | 78 | // Internal Variable 79 | extension UICollectionView { 80 | var collectionViewShimmer: CollectionViewShimmer? { 81 | get { 82 | return _collectionViewShimmer 83 | } 84 | set { 85 | self._collectionViewShimmer = newValue 86 | } 87 | } 88 | 89 | private var _collectionViewShimmer: CollectionViewShimmer? { 90 | get { 91 | if let shimmer = objc_getAssociatedObject(self, &_collectionViewShimmerAssociateObjectValue) as? CollectionViewShimmer { 92 | return shimmer 93 | } else { 94 | collectionViewShimmer = CollectionViewShimmer() 95 | return collectionViewShimmer 96 | } 97 | } 98 | set { 99 | return objc_setAssociatedObject(self, &_collectionViewShimmerAssociateObjectValue, 100 | newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN) 101 | } 102 | } 103 | } 104 | 105 | // Internal Shimmer protocol ( Delegate / DataSource ) 106 | internal protocol CollectionViewShimmerDelegate: UICollectionViewDelegate, UICollectionViewDataSource { } 107 | 108 | internal class CollectionViewShimmer: NSObject { 109 | var numberOfRows = 2 110 | var numberOfSections = 2 111 | var identifierCell = "" 112 | var delegateBeforeShimmer: UICollectionViewDelegate? 113 | var dataSourceBeforeShimmer: UICollectionViewDataSource? 114 | var animated = true 115 | 116 | var shimmerStartedKey = [Int]() 117 | 118 | override init() { } 119 | 120 | internal func shimmerStarted(_forKey key: Int) -> Bool { 121 | var finded = false 122 | for oldKey in shimmerStartedKey where oldKey == key { 123 | finded = true 124 | } 125 | return finded 126 | } 127 | } 128 | 129 | // MARK: - Collection Shimmer delegate 130 | extension CollectionViewShimmer: CollectionViewShimmerDelegate { 131 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 132 | return numberOfRows 133 | } 134 | 135 | func numberOfSections(in collectionView: UICollectionView) -> Int { 136 | return numberOfSections 137 | } 138 | 139 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 140 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifierCell, for: indexPath) 141 | return cell 142 | } 143 | } 144 | 145 | 146 | // MARK: - Intercepte Cell instantiation 147 | private func swizzle(_ vc: UICollectionView.Type) { 148 | [ 149 | (#selector(vc.dequeueReusableCell(withReuseIdentifier:for:)), #selector(vc.ksr_dequeueReusableCell(withReuseIdentifier:for:))), 150 | ].forEach { original, swizzled in 151 | 152 | guard let originalMethod = class_getInstanceMethod(vc, original), 153 | let swizzledMethod = class_getInstanceMethod(vc, swizzled) else { return } 154 | 155 | let didAddViewDidLoadMethod = class_addMethod(vc, 156 | original, 157 | method_getImplementation(swizzledMethod), 158 | method_getTypeEncoding(swizzledMethod)) 159 | 160 | if didAddViewDidLoadMethod { 161 | class_replaceMethod(vc, 162 | swizzled, 163 | method_getImplementation(originalMethod), 164 | method_getTypeEncoding(originalMethod)) 165 | } else { 166 | method_exchangeImplementations(originalMethod, swizzledMethod) 167 | } 168 | } 169 | } 170 | 171 | 172 | 173 | // MARK: - Swizzle method : Intercept all cell initialisation 174 | private var hasSwizzled = false 175 | extension UICollectionView { 176 | private final class func Swizzle() { 177 | guard !hasSwizzled else { return } 178 | hasSwizzled = true 179 | swizzle(self) 180 | } 181 | 182 | @objc func ksr_dequeueReusableCell(withReuseIdentifier identifier: String, for indexPath: IndexPath) -> UICollectionViewCell { 183 | 184 | let cell = self.ksr_dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) 185 | 186 | if collectionViewShimmer?.shimmerStarted(_forKey: hash) ?? false { 187 | cell.stopShimmerAnimation(animated: false) 188 | cell.startShimmerAnimation() 189 | } else { 190 | cell.stopShimmerAnimation(animated: false) 191 | } 192 | return cell 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /Example/ShimmerView/ShimmerView/UITableView+Shimmer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UITableView+Shimmer.swift 3 | // ShimmerView 4 | // 5 | // Created by Drouin on 23/07/2019. 6 | // Copyright © 2019 VersusMind. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | private var _tableViewShimmerAssociateObjectValue: Int = 1 12 | 13 | // Accessible Method 14 | extension UITableView { 15 | 16 | func startShimmerAnimation(withIdentifier: String, numberOfRows: Int? = 2, numberOfSections: Int? = 2) { 17 | // Activate Swizzle method ! 18 | UITableView.Swizzle() 19 | 20 | addTableViewKey(key: self.hash) 21 | 22 | tableViewShimmer?.numberOfRows = numberOfRows ?? 2 23 | tableViewShimmer?.numberOfSections = numberOfSections ?? 2 24 | tableViewShimmer?.identifierCell = withIdentifier 25 | tableViewShimmer?.delegateBeforeShimmer = self.delegate 26 | tableViewShimmer?.dataSourceBeforeShimmer = self.dataSource 27 | 28 | self.dataSource = tableViewShimmer 29 | self.delegate = tableViewShimmer 30 | 31 | UIView.transition(with: self, 32 | duration: 0.35, 33 | options: .transitionCrossDissolve, 34 | animations: { self.reloadData() }) 35 | } 36 | 37 | override func stopShimmerAnimation(animated: Bool = true) { 38 | removeTableViewKey(key: self.hash) 39 | if animated { 40 | UIView.transition(with: self, 41 | duration: 0.35, 42 | options: .transitionCrossDissolve, 43 | animations: { 44 | self.endShimmerReloadData() 45 | }) 46 | } else { 47 | endShimmerReloadData() 48 | } 49 | } 50 | } 51 | 52 | //UITableView Internal gestion method 53 | extension UITableView { 54 | private func endShimmerReloadData() { 55 | self.dataSource = self.tableViewShimmer?.dataSourceBeforeShimmer 56 | self.delegate = self.tableViewShimmer?.delegateBeforeShimmer 57 | self.reloadData() 58 | } 59 | 60 | private func addTableViewKey(key: Int) { 61 | var findedKey = false 62 | if let tableViewShimmer = tableViewShimmer { 63 | for oldKey in tableViewShimmer.shimmerStartedKey where oldKey == key { 64 | findedKey = true 65 | } 66 | 67 | if !findedKey { 68 | tableViewShimmer.shimmerStartedKey.append(key) 69 | } 70 | } 71 | } 72 | 73 | private func removeTableViewKey(key: Int) { 74 | if let tableViewShimmer = tableViewShimmer { 75 | for (index, oldKey) in tableViewShimmer.shimmerStartedKey.enumerated() where oldKey == key { 76 | tableViewShimmer.shimmerStartedKey.remove(at: index) 77 | } 78 | } 79 | } 80 | } 81 | 82 | // Internal Variable 83 | extension UITableView { 84 | internal var tableViewShimmer: TableViewShimmer? { 85 | get { 86 | return _tableViewShimmer 87 | } 88 | set { 89 | self._tableViewShimmer = newValue 90 | } 91 | } 92 | 93 | private var _tableViewShimmer: TableViewShimmer? { 94 | get { 95 | if let shimmer = objc_getAssociatedObject(self, &_tableViewShimmerAssociateObjectValue) as? TableViewShimmer { 96 | return shimmer 97 | } else { 98 | tableViewShimmer = TableViewShimmer() 99 | return tableViewShimmer 100 | } 101 | } 102 | set { 103 | return objc_setAssociatedObject(self, &_tableViewShimmerAssociateObjectValue, 104 | newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN) 105 | } 106 | } 107 | } 108 | 109 | // Internal Shimmer protocol ( Delegate / DataSource ) 110 | internal protocol TableViewShimmerDelegate: UITableViewDataSource, UITableViewDelegate { } 111 | 112 | internal class TableViewShimmer: NSObject { 113 | 114 | var numberOfRows = 2 115 | var numberOfSections = 2 116 | var identifierCell = "" 117 | var delegateBeforeShimmer: UITableViewDelegate? 118 | var dataSourceBeforeShimmer: UITableViewDataSource? 119 | 120 | var shimmerStartedKey = [Int]() 121 | 122 | override init() { } 123 | 124 | internal func shimmerStarted(_forKey key: Int) -> Bool { 125 | var finded = false 126 | for oldKey in shimmerStartedKey where oldKey == key { 127 | finded = true 128 | } 129 | return finded 130 | } 131 | } 132 | 133 | // Extension of Internal Shimmer protocol ( Delegate / DataSource ) 134 | extension TableViewShimmer: TableViewShimmerDelegate { 135 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 136 | return numberOfRows 137 | } 138 | 139 | func numberOfSections(in tableView: UITableView) -> Int { 140 | return numberOfSections 141 | } 142 | 143 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 144 | let cell = tableView.dequeueReusableCell(withIdentifier: identifierCell, for: indexPath) 145 | return cell 146 | } 147 | 148 | func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 149 | let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 28)) 150 | view.withShimmer = true 151 | shimmerStarted(_forKey: tableView.hash) ? view.startShimmerAnimation() : view.stopShimmerAnimation(animated: false) 152 | 153 | return view 154 | } 155 | } 156 | 157 | // Intercepte Cell instantiation 158 | private func swizzle(_ vc: UITableView.Type) { 159 | [ 160 | (#selector(vc.dequeueReusableCell(withIdentifier:)), #selector(vc.ksr_dequeueReusableCell(withIdentifier:))), 161 | ].forEach { original, swizzled in 162 | 163 | guard let originalMethod = class_getInstanceMethod(vc, original), 164 | let swizzledMethod = class_getInstanceMethod(vc, swizzled) else { return } 165 | 166 | let didAddViewDidLoadMethod = class_addMethod(vc, 167 | original, 168 | method_getImplementation(swizzledMethod), 169 | method_getTypeEncoding(swizzledMethod)) 170 | 171 | if didAddViewDidLoadMethod { 172 | class_replaceMethod(vc, 173 | swizzled, 174 | method_getImplementation(originalMethod), 175 | method_getTypeEncoding(originalMethod)) 176 | } else { 177 | method_exchangeImplementations(originalMethod, swizzledMethod) 178 | } 179 | } 180 | } 181 | 182 | private var hasSwizzled = false 183 | extension UITableView { 184 | private final class func Swizzle() { 185 | guard !hasSwizzled else { return } 186 | hasSwizzled = true 187 | swizzle(self) 188 | } 189 | 190 | @objc func ksr_dequeueReusableCell(withIdentifier identifier: String ) -> UITableViewCell? { 191 | let cell = self.ksr_dequeueReusableCell(withIdentifier: identifier) 192 | 193 | if tableViewShimmer?.shimmerStarted(_forKey: hash) ?? false { 194 | cell?.stopShimmerAnimation(animated: false) 195 | cell?.startShimmerAnimation() 196 | cell?.selectionStyle = .none 197 | } else { 198 | cell?.stopShimmerAnimation(animated: false) 199 | cell?.selectionStyle = .default 200 | } 201 | return cell 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /Example/ShimmerView/ShimmerView/UIView+Shimmer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Shimmer.swift 3 | // ShimmerView 4 | // 5 | // Created by Drouin on 24/06/2019. 6 | // Copyright © 2019 VersusMind. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | private var _withShimmerAssociateObjectValue: Int = 0 12 | extension UIView { 13 | 14 | private static let shimmer_tag = 9194 15 | 16 | @IBInspectable var withShimmer: Bool { 17 | get { return _withShimmer } 18 | set { self._withShimmer = newValue } 19 | } 20 | 21 | private var _withShimmer: Bool { 22 | get { return objc_getAssociatedObject(self, &_withShimmerAssociateObjectValue) as? Bool ?? false } 23 | set { return objc_setAssociatedObject(self, &_withShimmerAssociateObjectValue, 24 | newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN) } 25 | } 26 | 27 | @objc func startShimmerAnimation() { 28 | findShimmerAndActive(self) 29 | } 30 | 31 | private func findShimmerAndActive(_ view: UIView) { 32 | if view.withShimmer { 33 | addShimmerView(view) 34 | } 35 | for subView in view.subviews { 36 | findShimmerAndActive(subView) 37 | } 38 | } 39 | /* 40 | private func findShimmerAndActive(_ view: UIView) { 41 | if !view.withShimmer { 42 | for subView in view.subviews { 43 | if subView.withShimmer { 44 | addShimmerView(subView) 45 | } else { 46 | findShimmerAndActive(subView) 47 | } 48 | } 49 | } else { 50 | addShimmerView(view) 51 | } 52 | }*/ 53 | 54 | /* 55 | * Add shimmer view and start gradient animation 56 | */ 57 | private func addShimmerView(_ view: UIView) { 58 | let rectShimmer = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height) 59 | let shimmerView = UIView.init(frame: rectShimmer) 60 | 61 | let shimmerColor = (ShimmerOptions.instance.animationType == .classic) ? ShimmerOptions.instance.gradientColor : ShimmerOptions.instance.backgroundColor 62 | 63 | shimmerView.backgroundColor = shimmerColor 64 | shimmerView.tag = UIView.shimmer_tag 65 | ShimmerAnimation.buildAnimation(view: shimmerView, type: ShimmerOptions.instance.animationType) 66 | 67 | let rectBackground = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height) 68 | let shimmerViewBackground = UIView.init(frame: rectBackground) 69 | shimmerViewBackground.layer.cornerRadius = view.layer.cornerRadius 70 | 71 | let backgroundShimmer = (ShimmerOptions.instance.animationType == .classic) ? ShimmerOptions.instance.backgroundColor : UIColor.white 72 | 73 | shimmerViewBackground.backgroundColor = backgroundShimmer 74 | shimmerViewBackground.tag = UIView.shimmer_tag 75 | shimmerViewBackground.layer.borderWidth = ShimmerOptions.instance.borderWidth 76 | shimmerViewBackground.layer.borderColor = ShimmerOptions.instance.borderColor.cgColor 77 | shimmerViewBackground.layer.masksToBounds = true 78 | 79 | view.addSubview(shimmerViewBackground) 80 | shimmerViewBackground.addSubview(shimmerView) 81 | if let superView = view.superview { 82 | shimmerViewBackground.bringSubviewToFront(superView) 83 | superView.bringSubviewToFront(view) 84 | } 85 | } 86 | 87 | @objc func stopShimmerAnimation(animated: Bool = true) { 88 | removeShimmerView(self, animated: animated) 89 | } 90 | 91 | /* 92 | * Remove shimmer view and stop animation 93 | */ 94 | private func removeShimmerView(_ view: UIView, animated: Bool) { 95 | for subView in view.subviews { 96 | if subView.tag == UIView.shimmer_tag { 97 | if animated { 98 | UIView.animate(withDuration: 0.6, animations: { 99 | subView.alpha = 0 100 | }, completion: { _ in 101 | subView.removeFromSuperview() 102 | }) 103 | } else { 104 | subView.removeFromSuperview() 105 | } 106 | } else { 107 | removeShimmerView(subView, animated: animated) 108 | } 109 | } 110 | } 111 | } 112 | 113 | extension UIViewController { 114 | func startShimmerAnimation() { 115 | view.startShimmerAnimation() 116 | } 117 | func stopShimmerAnimation(animated: Bool = true) { 118 | view.stopShimmerAnimation(animated: animated) 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /Example/ShimmerView/TableViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewController.swift 3 | // ShimmerView 4 | // 5 | // Created by Drouin on 23/07/2019. 6 | // Copyright © 2019 VersusMind. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class TableViewController: UIViewController { 12 | @IBOutlet var tableView: UITableView! 13 | var shimmer = TableViewShimmer() 14 | 15 | 16 | var numberOfRowsInSection = 0 17 | var numberOfSections = 0 18 | 19 | override func viewDidLoad() { 20 | super.viewDidLoad() 21 | tableView.dataSource = self 22 | tableView.delegate = self 23 | } 24 | 25 | override func viewWillAppear(_ animated: Bool) { 26 | super.viewWillAppear(animated) 27 | } 28 | 29 | override func viewDidAppear(_ animated: Bool) { 30 | super.viewDidAppear(animated) 31 | 32 | self.tableView.startShimmerAnimation(withIdentifier: "shimmerCell", numberOfRows: 2, numberOfSections: 5) 33 | DispatchQueue.main.asyncAfter(deadline: .now() + 4.0, execute: { 34 | self.numberOfRowsInSection = 2 35 | self.numberOfSections = 3 36 | self.tableView.stopShimmerAnimation(animated: true) 37 | }) 38 | } 39 | } 40 | 41 | extension TableViewController: UITableViewDataSource, UITableViewDelegate { 42 | 43 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 44 | return numberOfRowsInSection 45 | } 46 | 47 | func numberOfSections(in tableView: UITableView) -> Int { 48 | return numberOfSections 49 | } 50 | 51 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 52 | let cell = tableView.dequeueReusableCell(withIdentifier: "shimmerCell", for: indexPath) 53 | cell.setNeedsLayout() 54 | cell.setNeedsDisplay() 55 | 56 | return cell 57 | } 58 | 59 | func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { 60 | return "Section \(section)" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Example/ShimmerView/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // ShimmerView 4 | // 5 | // Created by Drouin on 24/06/2019. 6 | // Copyright © 2019 VersusMind. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | @IBOutlet var label: UILabel! 14 | var on = true 15 | 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | } 19 | 20 | override func viewWillAppear(_ animated: Bool) { 21 | super.viewWillAppear(animated) 22 | ShimmerOptions.instance.backgroundColor = UIColor.red 23 | ShimmerOptions.instance.gradientColor = UIColor.green 24 | ShimmerOptions.instance.animationType = .fade 25 | startShimmerAnimation() 26 | } 27 | 28 | override func viewDidAppear(_ animated: Bool) { 29 | super.viewDidAppear(animated) 30 | } 31 | 32 | @IBAction func onOff() { 33 | if on { 34 | stopShimmerAnimation() 35 | } else { 36 | startShimmerAnimation() 37 | } 38 | 39 | on = !on 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2019 LeBzul 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Platform](https://img.shields.io/badge/Platform-iOS-green.svg) 2 | ![Language](https://img.shields.io/badge/Swift-4-blue.svg) 3 | 4 | # SimpleShimmer 5 | 6 | ![Img](https://github.com/LeBzul/SimpleShimmer/blob/master/example_images/tableview_shimmer_classic.gif) 7 | 8 | ![Img](https://github.com/LeBzul/SimpleShimmer/blob/master/example_images/classic_shimmer.gif) 9 | ![Img](https://github.com/LeBzul/SimpleShimmer/blob/master/example_images/fade_shimmer.gif) 10 | 11 | ![Img](https://github.com/LeBzul/SimpleShimmer/blob/master/example_images/classic_shimmer_color.gif) 12 | ![Img](https://github.com/LeBzul/SimpleShimmer/blob/master/example_images/classic_shimmer_color_no_border.gif) 13 | 14 | 15 | 16 | ## Installation 17 | 18 | Import SimpleShimmer folder in your project (or use example project) 19 | 20 | ## Usage 21 | 22 | Activate UIView Shimmer in InterfaceBuilder : 23 | 24 | ![Img](https://github.com/LeBzul/SimpleShimmer/blob/master/example_images/activate_shimmer.png) 25 | 26 | 27 | 28 | Or programmatically : 29 | ```Swift 30 | myView.withShimmer = true 31 | ``` 32 | 33 | ### Start shimmer 34 | 35 | For a specific (activated) UIView : 36 | 37 | ```Swift 38 | myView.startShimmerAnimation() 39 | myView.stopShimmerAnimation() 40 | ``` 41 | 42 | For all (activated) UIView in UIViewController : 43 | 44 | ```Swift 45 | startShimmerAnimation() 46 | stopShimmerAnimation() 47 | ``` 48 | 49 | For cell in UITableView or UICollectionView : 50 | ```Swift 51 | myTableView.startShimmerAnimation(withIdentifier: "shimmerCell", numberOfRows: 2, numberOfSections: 5) 52 | myTableView.stopShimmerAnimation() 53 | myCollectionView.startShimmerAnimation(withIdentifier: "collectionShimmerCell", numberOfRows: 2, numberOfSections: 5) 54 | myCollectionView.stopShimmerAnimation() 55 | ``` 56 | 57 | ### ShimmerOptions 58 | 59 | Change animation type : 60 | 61 | ```Swift 62 | ShimmerOptions.instance.animationType = .classic 63 | ``` 64 | 65 | | .classic | .fade | 66 | | ------------- | ------------- | 67 | | ![Img](https://github.com/LeBzul/SimpleShimmer/blob/master/example_images/classic_shimmer.gif) | ![Img](https://github.com/LeBzul/SimpleShimmer/blob/master/example_images/fade_shimmer.gif) | 68 | 69 | ##### Animation properties : 70 | 71 | | Properties | Possible value | Comment | 72 | | ------------- | ------------- | ------------- | 73 | | animationDuration | CGFloat | Change animation duration | 74 | | animationDelay | CGFloat | Delay to restart animation after end | 75 | | animationAutoReserse | Bool | Reverse animation | 76 | | animationDirection | topBottom, bottomTop, leftRight, rightLeft | Change animation direction (for animation type classic) | 77 | | gradientColor | UIColor | Change gradient color (for animation type classic) | 78 | 79 | ##### Shimmer style : 80 | 81 | | Properties | Possible value | Comment | 82 | | ------------- | ------------- | ------------- | 83 | | gradientColor | UIColor | Change gradient color (for animation type classic) | 84 | | borderWidth | CGFloat | Add border to Shimmer view | 85 | | borderColor | UIColor | Change color to Shimmer view | 86 | | backgroundColor | UIColor | Change background color to Shimmer view | 87 | 88 | 89 | ## Author 90 | 91 | Guillian Drouin, drouingui@gmail.com 92 | 93 | # License 94 | SimpleShimmer is available under the MIT license. See the [LICENSE](LICENSE) file for more info. 95 | If you use it, I'll be happy to know about it. 96 | -------------------------------------------------------------------------------- /ShimmerView/ShimmerAnimation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ShimmerAnimation.swift 3 | // ShimmerView 4 | // 5 | // Created by Drouin on 29/07/2019. 6 | // Copyright © 2019 VersusMind. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ShimmerAnimation { 12 | 13 | static func buildAnimation(view: UIView, type: ShimmerOptions.AnimationType) { 14 | switch type { 15 | case .classic: buildClassicAnimation(view: view) 16 | case .fade: buildFadeAnimation(view: view) 17 | } 18 | } 19 | 20 | static private func buildFadeAnimation(view: UIView) { 21 | let animation = CABasicAnimation(keyPath: "opacity") 22 | animation.fromValue = 0.9 23 | animation.toValue = 0.3 24 | let realDuration = ShimmerOptions.instance.animationAutoReserse ? (ShimmerOptions.instance.animationDuration * 2) : ShimmerOptions.instance.animationDuration 25 | animation.duration = CFTimeInterval(realDuration + ShimmerOptions.instance.animationDelay) 26 | animation.repeatCount = HUGE 27 | animation.autoreverses = ShimmerOptions.instance.animationAutoReserse 28 | 29 | animation.fillMode = CAMediaTimingFillMode.forwards 30 | animation.isRemovedOnCompletion = false 31 | animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut) 32 | view.layer.add(animation, forKey: "fade") 33 | } 34 | 35 | static private func buildClassicAnimation(view: UIView) { 36 | 37 | let animation = CABasicAnimation(keyPath: "transform.translation.x") 38 | animation.duration = CFTimeInterval(ShimmerOptions.instance.animationDuration) 39 | 40 | var fromValue: CGFloat = 0 41 | var toValue: CGFloat = 0 42 | switch ShimmerOptions.instance.animationDirection { 43 | case .topBottom: 44 | animation.keyPath = "transform.translation.y" 45 | fromValue = -view.frame.size.height 46 | toValue = view.frame.size.height 47 | case .bottomTop: 48 | animation.keyPath = "transform.translation.y" 49 | fromValue = view.frame.size.height 50 | toValue = -view.frame.size.height 51 | case .leftRight: 52 | fromValue = -view.frame.size.width 53 | toValue = view.frame.size.width 54 | case .rightLeft: 55 | fromValue = view.frame.size.width 56 | toValue = -view.frame.size.width 57 | } 58 | 59 | animation.fromValue = fromValue 60 | animation.toValue = toValue 61 | animation.fillMode = CAMediaTimingFillMode.forwards 62 | animation.isRemovedOnCompletion = false 63 | animation.autoreverses = ShimmerOptions.instance.animationAutoReserse 64 | 65 | let group = CAAnimationGroup() 66 | group.animations = [animation] 67 | let realDuration = ShimmerOptions.instance.animationAutoReserse ? (ShimmerOptions.instance.animationDuration * 2) : ShimmerOptions.instance.animationDuration 68 | group.duration = CFTimeInterval(realDuration + ShimmerOptions.instance.animationDelay) 69 | group.repeatCount = HUGE 70 | 71 | let gradientLayer = CAGradientLayer() 72 | gradientLayer.colors = [UIColor.clear.cgColor, UIColor.white.cgColor, UIColor.clear.cgColor] 73 | gradientLayer.frame = view.bounds 74 | 75 | switch ShimmerOptions.instance.animationDirection { 76 | case .topBottom, .bottomTop: 77 | gradientLayer.startPoint = CGPoint(x: 1.0, y: 1.0) 78 | gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.0) 79 | case .leftRight, .rightLeft: 80 | gradientLayer.startPoint = CGPoint(x: 1.0, y: 1.0) 81 | gradientLayer.endPoint = CGPoint(x: 0.0, y: 1.0) 82 | } 83 | 84 | gradientLayer.add(group, forKey: "animationShimmerView") 85 | view.layer.mask = gradientLayer 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /ShimmerView/ShimmerOptions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwimmerOptions.swift 3 | // ShimmerView 4 | // 5 | // Created by Drouin on 26/07/2019. 6 | // Copyright © 2019 VersusMind. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public class ShimmerOptions { 12 | public static let instance = ShimmerOptions() 13 | 14 | enum Direction { 15 | case topBottom 16 | case bottomTop 17 | case leftRight 18 | case rightLeft 19 | } 20 | 21 | enum AnimationType { 22 | case classic 23 | case fade 24 | } 25 | 26 | // Animation option 27 | var animationDuration: CGFloat = 1.0 28 | var animationDelay: CGFloat = 0.3 29 | var animationAutoReserse = true 30 | var animationDirection: Direction = .leftRight 31 | var animationType: AnimationType = .classic 32 | 33 | // Shimmer background option 34 | var gradientColor = UIColor.gray 35 | var borderWidth: CGFloat = 0.0 36 | var borderColor = UIColor.gray 37 | var backgroundColor = UIColor.white 38 | 39 | private init() { } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /ShimmerView/UICollectionView+Shimmer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UICollectionView+Shimmer.swift 3 | // ShimmerView 4 | // 5 | // Created by Drouin on 23/07/2019. 6 | // Copyright © 2019 VersusMind. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | private var _collectionViewShimmerAssociateObjectValue: Int = 2 12 | 13 | 14 | // Accessible Method 15 | extension UICollectionView { 16 | func startShimmerAnimation(withIdentifier: String, numberOfRows: Int? = 2, numberOfSections: Int? = 2) { 17 | // Activate Swizzle method ! 18 | UICollectionView.Swizzle() 19 | 20 | addCollectionViewKey(key: self.hash) 21 | collectionViewShimmer?.numberOfRows = numberOfRows ?? 2 22 | collectionViewShimmer?.numberOfSections = numberOfSections ?? 2 23 | collectionViewShimmer?.identifierCell = withIdentifier 24 | collectionViewShimmer?.delegateBeforeShimmer = self.delegate 25 | collectionViewShimmer?.dataSourceBeforeShimmer = self.dataSource 26 | 27 | self.dataSource = collectionViewShimmer 28 | self.delegate = collectionViewShimmer 29 | self.reloadData() 30 | } 31 | 32 | override func stopShimmerAnimation(animated: Bool = true) { 33 | removeCollectionViewKey(key: self.hash) 34 | if animated { 35 | UIView.transition(with: self, 36 | duration: 0.35, 37 | options: .transitionCrossDissolve, 38 | animations: { 39 | self.endShimmerReloadData() 40 | }) 41 | } else { 42 | endShimmerReloadData() 43 | } 44 | } 45 | } 46 | 47 | //UICollectionView Internal gestion method 48 | extension UICollectionView { 49 | private func endShimmerReloadData() { 50 | self.dataSource = self.collectionViewShimmer?.dataSourceBeforeShimmer 51 | self.delegate = self.collectionViewShimmer?.delegateBeforeShimmer 52 | self.reloadData() 53 | } 54 | 55 | private func addCollectionViewKey(key: Int) { 56 | var findedKey = false 57 | if let collectionViewShimmer = collectionViewShimmer { 58 | for oldKey in collectionViewShimmer.shimmerStartedKey where oldKey == key { 59 | findedKey = true 60 | } 61 | 62 | if !findedKey { 63 | collectionViewShimmer.shimmerStartedKey.append(key) 64 | } 65 | } 66 | } 67 | 68 | private func removeCollectionViewKey(key: Int) { 69 | if let collectionViewShimmer = collectionViewShimmer { 70 | for (index, oldKey) in collectionViewShimmer.shimmerStartedKey.enumerated() where oldKey == key { 71 | collectionViewShimmer.shimmerStartedKey.remove(at: index) 72 | } 73 | } 74 | } 75 | } 76 | 77 | 78 | // Internal Variable 79 | extension UICollectionView { 80 | var collectionViewShimmer: CollectionViewShimmer? { 81 | get { 82 | return _collectionViewShimmer 83 | } 84 | set { 85 | self._collectionViewShimmer = newValue 86 | } 87 | } 88 | 89 | private var _collectionViewShimmer: CollectionViewShimmer? { 90 | get { 91 | if let shimmer = objc_getAssociatedObject(self, &_collectionViewShimmerAssociateObjectValue) as? CollectionViewShimmer { 92 | return shimmer 93 | } else { 94 | collectionViewShimmer = CollectionViewShimmer() 95 | return collectionViewShimmer 96 | } 97 | } 98 | set { 99 | return objc_setAssociatedObject(self, &_collectionViewShimmerAssociateObjectValue, 100 | newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN) 101 | } 102 | } 103 | } 104 | 105 | // Internal Shimmer protocol ( Delegate / DataSource ) 106 | internal protocol CollectionViewShimmerDelegate: UICollectionViewDelegate, UICollectionViewDataSource { } 107 | 108 | internal class CollectionViewShimmer: NSObject { 109 | var numberOfRows = 2 110 | var numberOfSections = 2 111 | var identifierCell = "" 112 | var delegateBeforeShimmer: UICollectionViewDelegate? 113 | var dataSourceBeforeShimmer: UICollectionViewDataSource? 114 | var animated = true 115 | 116 | var shimmerStartedKey = [Int]() 117 | 118 | override init() { } 119 | 120 | internal func shimmerStarted(_forKey key: Int) -> Bool { 121 | var finded = false 122 | for oldKey in shimmerStartedKey where oldKey == key { 123 | finded = true 124 | } 125 | return finded 126 | } 127 | } 128 | 129 | // MARK: - Collection Shimmer delegate 130 | extension CollectionViewShimmer: CollectionViewShimmerDelegate { 131 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 132 | return numberOfRows 133 | } 134 | 135 | func numberOfSections(in collectionView: UICollectionView) -> Int { 136 | return numberOfSections 137 | } 138 | 139 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 140 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifierCell, for: indexPath) 141 | return cell 142 | } 143 | } 144 | 145 | 146 | // MARK: - Intercepte Cell instantiation 147 | private func swizzle(_ vc: UICollectionView.Type) { 148 | [ 149 | (#selector(vc.dequeueReusableCell(withReuseIdentifier:for:)), #selector(vc.ksr_dequeueReusableCell(withReuseIdentifier:for:))), 150 | ].forEach { original, swizzled in 151 | 152 | guard let originalMethod = class_getInstanceMethod(vc, original), 153 | let swizzledMethod = class_getInstanceMethod(vc, swizzled) else { return } 154 | 155 | let didAddViewDidLoadMethod = class_addMethod(vc, 156 | original, 157 | method_getImplementation(swizzledMethod), 158 | method_getTypeEncoding(swizzledMethod)) 159 | 160 | if didAddViewDidLoadMethod { 161 | class_replaceMethod(vc, 162 | swizzled, 163 | method_getImplementation(originalMethod), 164 | method_getTypeEncoding(originalMethod)) 165 | } else { 166 | method_exchangeImplementations(originalMethod, swizzledMethod) 167 | } 168 | } 169 | } 170 | 171 | 172 | 173 | // MARK: - Swizzle method : Intercept all cell initialisation 174 | private var hasSwizzled = false 175 | extension UICollectionView { 176 | private final class func Swizzle() { 177 | guard !hasSwizzled else { return } 178 | hasSwizzled = true 179 | swizzle(self) 180 | } 181 | 182 | @objc func ksr_dequeueReusableCell(withReuseIdentifier identifier: String, for indexPath: IndexPath) -> UICollectionViewCell { 183 | 184 | let cell = self.ksr_dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) 185 | 186 | if collectionViewShimmer?.shimmerStarted(_forKey: hash) ?? false { 187 | cell.stopShimmerAnimation(animated: false) 188 | cell.startShimmerAnimation() 189 | } else { 190 | cell.stopShimmerAnimation(animated: false) 191 | } 192 | return cell 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /ShimmerView/UITableView+Shimmer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UITableView+Shimmer.swift 3 | // ShimmerView 4 | // 5 | // Created by Drouin on 23/07/2019. 6 | // Copyright © 2019 VersusMind. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | private var _tableViewShimmerAssociateObjectValue: Int = 1 12 | 13 | // Accessible Method 14 | extension UITableView { 15 | 16 | func startShimmerAnimation(withIdentifier: String, numberOfRows: Int? = 2, numberOfSections: Int? = 2) { 17 | // Activate Swizzle method ! 18 | UITableView.Swizzle() 19 | 20 | addTableViewKey(key: self.hash) 21 | 22 | tableViewShimmer?.numberOfRows = numberOfRows ?? 2 23 | tableViewShimmer?.numberOfSections = numberOfSections ?? 2 24 | tableViewShimmer?.identifierCell = withIdentifier 25 | tableViewShimmer?.delegateBeforeShimmer = self.delegate 26 | tableViewShimmer?.dataSourceBeforeShimmer = self.dataSource 27 | 28 | self.dataSource = tableViewShimmer 29 | self.delegate = tableViewShimmer 30 | 31 | UIView.transition(with: self, 32 | duration: 0.35, 33 | options: .transitionCrossDissolve, 34 | animations: { self.reloadData() }) 35 | } 36 | 37 | override func stopShimmerAnimation(animated: Bool = true) { 38 | removeTableViewKey(key: self.hash) 39 | if animated { 40 | UIView.transition(with: self, 41 | duration: 0.35, 42 | options: .transitionCrossDissolve, 43 | animations: { 44 | self.endShimmerReloadData() 45 | }) 46 | } else { 47 | endShimmerReloadData() 48 | } 49 | } 50 | } 51 | 52 | //UITableView Internal gestion method 53 | extension UITableView { 54 | private func endShimmerReloadData() { 55 | self.dataSource = self.tableViewShimmer?.dataSourceBeforeShimmer 56 | self.delegate = self.tableViewShimmer?.delegateBeforeShimmer 57 | self.reloadData() 58 | } 59 | 60 | private func addTableViewKey(key: Int) { 61 | var findedKey = false 62 | if let tableViewShimmer = tableViewShimmer { 63 | for oldKey in tableViewShimmer.shimmerStartedKey where oldKey == key { 64 | findedKey = true 65 | } 66 | 67 | if !findedKey { 68 | tableViewShimmer.shimmerStartedKey.append(key) 69 | } 70 | } 71 | } 72 | 73 | private func removeTableViewKey(key: Int) { 74 | if let tableViewShimmer = tableViewShimmer { 75 | for (index, oldKey) in tableViewShimmer.shimmerStartedKey.enumerated() where oldKey == key { 76 | tableViewShimmer.shimmerStartedKey.remove(at: index) 77 | } 78 | } 79 | } 80 | } 81 | 82 | // Internal Variable 83 | extension UITableView { 84 | internal var tableViewShimmer: TableViewShimmer? { 85 | get { 86 | return _tableViewShimmer 87 | } 88 | set { 89 | self._tableViewShimmer = newValue 90 | } 91 | } 92 | 93 | private var _tableViewShimmer: TableViewShimmer? { 94 | get { 95 | if let shimmer = objc_getAssociatedObject(self, &_tableViewShimmerAssociateObjectValue) as? TableViewShimmer { 96 | return shimmer 97 | } else { 98 | tableViewShimmer = TableViewShimmer() 99 | return tableViewShimmer 100 | } 101 | } 102 | set { 103 | return objc_setAssociatedObject(self, &_tableViewShimmerAssociateObjectValue, 104 | newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN) 105 | } 106 | } 107 | } 108 | 109 | // Internal Shimmer protocol ( Delegate / DataSource ) 110 | internal protocol TableViewShimmerDelegate: UITableViewDataSource, UITableViewDelegate { } 111 | 112 | internal class TableViewShimmer: NSObject { 113 | 114 | var numberOfRows = 2 115 | var numberOfSections = 2 116 | var identifierCell = "" 117 | var delegateBeforeShimmer: UITableViewDelegate? 118 | var dataSourceBeforeShimmer: UITableViewDataSource? 119 | 120 | var shimmerStartedKey = [Int]() 121 | 122 | override init() { } 123 | 124 | internal func shimmerStarted(_forKey key: Int) -> Bool { 125 | var finded = false 126 | for oldKey in shimmerStartedKey where oldKey == key { 127 | finded = true 128 | } 129 | return finded 130 | } 131 | } 132 | 133 | // Extension of Internal Shimmer protocol ( Delegate / DataSource ) 134 | extension TableViewShimmer: TableViewShimmerDelegate { 135 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 136 | return numberOfRows 137 | } 138 | 139 | func numberOfSections(in tableView: UITableView) -> Int { 140 | return numberOfSections 141 | } 142 | 143 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 144 | let cell = tableView.dequeueReusableCell(withIdentifier: identifierCell, for: indexPath) 145 | return cell 146 | } 147 | 148 | func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 149 | let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 28)) 150 | view.withShimmer = true 151 | shimmerStarted(_forKey: tableView.hash) ? view.startShimmerAnimation() : view.stopShimmerAnimation(animated: false) 152 | 153 | return view 154 | } 155 | } 156 | 157 | // Intercepte Cell instantiation 158 | private func swizzle(_ vc: UITableView.Type) { 159 | [ 160 | (#selector(vc.dequeueReusableCell(withIdentifier:)), #selector(vc.ksr_dequeueReusableCell(withIdentifier:))), 161 | ].forEach { original, swizzled in 162 | 163 | guard let originalMethod = class_getInstanceMethod(vc, original), 164 | let swizzledMethod = class_getInstanceMethod(vc, swizzled) else { return } 165 | 166 | let didAddViewDidLoadMethod = class_addMethod(vc, 167 | original, 168 | method_getImplementation(swizzledMethod), 169 | method_getTypeEncoding(swizzledMethod)) 170 | 171 | if didAddViewDidLoadMethod { 172 | class_replaceMethod(vc, 173 | swizzled, 174 | method_getImplementation(originalMethod), 175 | method_getTypeEncoding(originalMethod)) 176 | } else { 177 | method_exchangeImplementations(originalMethod, swizzledMethod) 178 | } 179 | } 180 | } 181 | 182 | private var hasSwizzled = false 183 | extension UITableView { 184 | private final class func Swizzle() { 185 | guard !hasSwizzled else { return } 186 | hasSwizzled = true 187 | swizzle(self) 188 | } 189 | 190 | @objc func ksr_dequeueReusableCell(withIdentifier identifier: String ) -> UITableViewCell? { 191 | let cell = self.ksr_dequeueReusableCell(withIdentifier: identifier) 192 | 193 | if tableViewShimmer?.shimmerStarted(_forKey: hash) ?? false { 194 | cell?.stopShimmerAnimation(animated: false) 195 | cell?.startShimmerAnimation() 196 | cell?.selectionStyle = .none 197 | } else { 198 | cell?.stopShimmerAnimation(animated: false) 199 | cell?.selectionStyle = .default 200 | } 201 | return cell 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /ShimmerView/UIView+Shimmer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Shimmer.swift 3 | // ShimmerView 4 | // 5 | // Created by Drouin on 24/06/2019. 6 | // Copyright © 2019 VersusMind. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | private var _withShimmerAssociateObjectValue: Int = 0 12 | extension UIView { 13 | 14 | private static let shimmer_tag = 9194 15 | 16 | @IBInspectable var withShimmer: Bool { 17 | get { return _withShimmer } 18 | set { self._withShimmer = newValue } 19 | } 20 | 21 | private var _withShimmer: Bool { 22 | get { return objc_getAssociatedObject(self, &_withShimmerAssociateObjectValue) as? Bool ?? false } 23 | set { return objc_setAssociatedObject(self, &_withShimmerAssociateObjectValue, 24 | newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN) } 25 | } 26 | 27 | @objc func startShimmerAnimation() { 28 | findShimmerAndActive(self) 29 | } 30 | 31 | private func findShimmerAndActive(_ view: UIView) { 32 | if view.withShimmer { 33 | addShimmerView(view) 34 | } 35 | for subView in view.subviews { 36 | findShimmerAndActive(subView) 37 | } 38 | } 39 | /* 40 | private func findShimmerAndActive(_ view: UIView) { 41 | if !view.withShimmer { 42 | for subView in view.subviews { 43 | if subView.withShimmer { 44 | addShimmerView(subView) 45 | } else { 46 | findShimmerAndActive(subView) 47 | } 48 | } 49 | } else { 50 | addShimmerView(view) 51 | } 52 | }*/ 53 | 54 | /* 55 | * Add shimmer view and start gradient animation 56 | */ 57 | private func addShimmerView(_ view: UIView) { 58 | let rectShimmer = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height) 59 | let shimmerView = UIView.init(frame: rectShimmer) 60 | 61 | let shimmerColor = (ShimmerOptions.instance.animationType == .classic) ? ShimmerOptions.instance.gradientColor : ShimmerOptions.instance.backgroundColor 62 | 63 | shimmerView.backgroundColor = shimmerColor 64 | shimmerView.tag = UIView.shimmer_tag 65 | ShimmerAnimation.buildAnimation(view: shimmerView, type: ShimmerOptions.instance.animationType) 66 | 67 | let rectBackground = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height) 68 | let shimmerViewBackground = UIView.init(frame: rectBackground) 69 | shimmerViewBackground.layer.cornerRadius = view.layer.cornerRadius 70 | 71 | let backgroundShimmer = (ShimmerOptions.instance.animationType == .classic) ? ShimmerOptions.instance.backgroundColor : UIColor.white 72 | 73 | shimmerViewBackground.backgroundColor = backgroundShimmer 74 | shimmerViewBackground.tag = UIView.shimmer_tag 75 | shimmerViewBackground.layer.borderWidth = ShimmerOptions.instance.borderWidth 76 | shimmerViewBackground.layer.borderColor = ShimmerOptions.instance.borderColor.cgColor 77 | shimmerViewBackground.layer.masksToBounds = true 78 | 79 | view.addSubview(shimmerViewBackground) 80 | shimmerViewBackground.addSubview(shimmerView) 81 | if let superView = view.superview { 82 | shimmerViewBackground.bringSubviewToFront(superView) 83 | superView.bringSubviewToFront(view) 84 | } 85 | } 86 | 87 | @objc func stopShimmerAnimation(animated: Bool = true) { 88 | removeShimmerView(self, animated: animated) 89 | } 90 | 91 | /* 92 | * Remove shimmer view and stop animation 93 | */ 94 | private func removeShimmerView(_ view: UIView, animated: Bool) { 95 | for subView in view.subviews { 96 | if subView.tag == UIView.shimmer_tag { 97 | if animated { 98 | UIView.animate(withDuration: 0.6, animations: { 99 | subView.alpha = 0 100 | }, completion: { _ in 101 | subView.removeFromSuperview() 102 | }) 103 | } else { 104 | subView.removeFromSuperview() 105 | } 106 | } else { 107 | removeShimmerView(subView, animated: animated) 108 | } 109 | } 110 | } 111 | } 112 | 113 | extension UIViewController { 114 | func startShimmerAnimation() { 115 | view.startShimmerAnimation() 116 | } 117 | func stopShimmerAnimation(animated: Bool = true) { 118 | view.stopShimmerAnimation(animated: animated) 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /example_images/activate_shimmer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeBzul/SimpleShimmer/25dd66fde477d26e70c77b5f5b63d35116c94b15/example_images/activate_shimmer.png -------------------------------------------------------------------------------- /example_images/activate_shimmer_IB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeBzul/SimpleShimmer/25dd66fde477d26e70c77b5f5b63d35116c94b15/example_images/activate_shimmer_IB.png -------------------------------------------------------------------------------- /example_images/classic_shimmer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeBzul/SimpleShimmer/25dd66fde477d26e70c77b5f5b63d35116c94b15/example_images/classic_shimmer.gif -------------------------------------------------------------------------------- /example_images/classic_shimmer_color.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeBzul/SimpleShimmer/25dd66fde477d26e70c77b5f5b63d35116c94b15/example_images/classic_shimmer_color.gif -------------------------------------------------------------------------------- /example_images/classic_shimmer_color_no_border.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeBzul/SimpleShimmer/25dd66fde477d26e70c77b5f5b63d35116c94b15/example_images/classic_shimmer_color_no_border.gif -------------------------------------------------------------------------------- /example_images/fade_shimmer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeBzul/SimpleShimmer/25dd66fde477d26e70c77b5f5b63d35116c94b15/example_images/fade_shimmer.gif -------------------------------------------------------------------------------- /example_images/tableview_shimmer_classic.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeBzul/SimpleShimmer/25dd66fde477d26e70c77b5f5b63d35116c94b15/example_images/tableview_shimmer_classic.gif --------------------------------------------------------------------------------