├── .gitignore ├── CCAnimations.podspec ├── CCAnimations ├── CCAnimations.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcuserdata │ │ └── carlos.correa.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ ├── CCAnimations.xcscheme │ │ └── xcschememanagement.plist ├── CCAnimations │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Contents.json │ │ └── heman.imageset │ │ │ ├── Contents.json │ │ │ └── heman.jpg │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ └── ViewController.swift └── demo │ ├── 1.gif │ ├── 10.gif │ ├── 11.gif │ ├── 12.gif │ ├── 2.gif │ ├── 3.gif │ ├── 4.gif │ ├── 5.gif │ ├── 6.gif │ ├── 7.gif │ ├── 8.gif │ └── 9.gif ├── LICENSE ├── README.md └── Source └── CCAnimations.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | .DS_Store 20 | 21 | # CocoaPods 22 | # 23 | # We recommend against adding the Pods directory to your .gitignore. However 24 | # you should judge for yourself, the pros and cons are mentioned at: 25 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 26 | # 27 | # Pods/ 28 | 29 | # Carthage 30 | # 31 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 32 | # Carthage/Checkouts 33 | 34 | Carthage/Build 35 | -------------------------------------------------------------------------------- /CCAnimations.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'CCAnimations' 3 | s.version = '0.0.2' 4 | s.summary = 'Custom CAAnimations' 5 | 6 | s.description = <<-DESC 7 | A set of custom CAAnimations. 8 | DESC 9 | 10 | s.homepage = 'https://github.com/caiobzen/CCAnimations' 11 | 12 | s.license ='MIT' 13 | 14 | s.author = { 'Carlos Corrêa' => 'caiobzen@gmail.com' } 15 | s.social_media_url = 'http://twitter.com/caiobzen' 16 | 17 | s.ios.deployment_target = '9.0' 18 | s.requires_arc = true 19 | 20 | s.source = { :git => 'https://github.com/caiobzen/CCAnimations.git', :tag => s.version } 21 | s.source_files = 'Source/*.swift' 22 | 23 | end 24 | -------------------------------------------------------------------------------- /CCAnimations/CCAnimations.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | BAE10B491CBC2A8F009E9EBD /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAE10B481CBC2A8F009E9EBD /* AppDelegate.swift */; }; 11 | BAE10B4B1CBC2A8F009E9EBD /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAE10B4A1CBC2A8F009E9EBD /* ViewController.swift */; }; 12 | BAE10B4E1CBC2A8F009E9EBD /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BAE10B4C1CBC2A8F009E9EBD /* Main.storyboard */; }; 13 | BAE10B501CBC2A8F009E9EBD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BAE10B4F1CBC2A8F009E9EBD /* Assets.xcassets */; }; 14 | BAE10B531CBC2A8F009E9EBD /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BAE10B511CBC2A8F009E9EBD /* LaunchScreen.storyboard */; }; 15 | BAE10B641CBC378F009E9EBD /* CCAnimations.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAE10B631CBC378F009E9EBD /* CCAnimations.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | BAE10B451CBC2A8F009E9EBD /* CCAnimations.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CCAnimations.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | BAE10B481CBC2A8F009E9EBD /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 21 | BAE10B4A1CBC2A8F009E9EBD /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 22 | BAE10B4D1CBC2A8F009E9EBD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 23 | BAE10B4F1CBC2A8F009E9EBD /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | BAE10B521CBC2A8F009E9EBD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 25 | BAE10B541CBC2A8F009E9EBD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 26 | BAE10B631CBC378F009E9EBD /* CCAnimations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CCAnimations.swift; path = ../../Source/CCAnimations.swift; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | BAE10B421CBC2A8F009E9EBD /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | BAE10B3C1CBC2A8F009E9EBD = { 41 | isa = PBXGroup; 42 | children = ( 43 | BAE10B471CBC2A8F009E9EBD /* CCAnimations */, 44 | BAE10B461CBC2A8F009E9EBD /* Products */, 45 | ); 46 | sourceTree = ""; 47 | }; 48 | BAE10B461CBC2A8F009E9EBD /* Products */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | BAE10B451CBC2A8F009E9EBD /* CCAnimations.app */, 52 | ); 53 | name = Products; 54 | sourceTree = ""; 55 | }; 56 | BAE10B471CBC2A8F009E9EBD /* CCAnimations */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | BAE10B5C1CBC33C7009E9EBD /* Source */, 60 | BAE10B481CBC2A8F009E9EBD /* AppDelegate.swift */, 61 | BAE10B4A1CBC2A8F009E9EBD /* ViewController.swift */, 62 | BAE10B4C1CBC2A8F009E9EBD /* Main.storyboard */, 63 | BAE10B4F1CBC2A8F009E9EBD /* Assets.xcassets */, 64 | BAE10B511CBC2A8F009E9EBD /* LaunchScreen.storyboard */, 65 | BAE10B541CBC2A8F009E9EBD /* Info.plist */, 66 | ); 67 | path = CCAnimations; 68 | sourceTree = ""; 69 | }; 70 | BAE10B5C1CBC33C7009E9EBD /* Source */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | BAE10B631CBC378F009E9EBD /* CCAnimations.swift */, 74 | ); 75 | name = Source; 76 | sourceTree = ""; 77 | }; 78 | /* End PBXGroup section */ 79 | 80 | /* Begin PBXNativeTarget section */ 81 | BAE10B441CBC2A8F009E9EBD /* CCAnimations */ = { 82 | isa = PBXNativeTarget; 83 | buildConfigurationList = BAE10B571CBC2A8F009E9EBD /* Build configuration list for PBXNativeTarget "CCAnimations" */; 84 | buildPhases = ( 85 | BAE10B411CBC2A8F009E9EBD /* Sources */, 86 | BAE10B421CBC2A8F009E9EBD /* Frameworks */, 87 | BAE10B431CBC2A8F009E9EBD /* Resources */, 88 | ); 89 | buildRules = ( 90 | ); 91 | dependencies = ( 92 | ); 93 | name = CCAnimations; 94 | productName = CCAnimations; 95 | productReference = BAE10B451CBC2A8F009E9EBD /* CCAnimations.app */; 96 | productType = "com.apple.product-type.application"; 97 | }; 98 | /* End PBXNativeTarget section */ 99 | 100 | /* Begin PBXProject section */ 101 | BAE10B3D1CBC2A8F009E9EBD /* Project object */ = { 102 | isa = PBXProject; 103 | attributes = { 104 | LastSwiftUpdateCheck = 0730; 105 | LastUpgradeCheck = 0730; 106 | ORGANIZATIONNAME = "Carlos Corrêa"; 107 | TargetAttributes = { 108 | BAE10B441CBC2A8F009E9EBD = { 109 | CreatedOnToolsVersion = 7.3; 110 | }; 111 | }; 112 | }; 113 | buildConfigurationList = BAE10B401CBC2A8F009E9EBD /* Build configuration list for PBXProject "CCAnimations" */; 114 | compatibilityVersion = "Xcode 3.2"; 115 | developmentRegion = English; 116 | hasScannedForEncodings = 0; 117 | knownRegions = ( 118 | en, 119 | Base, 120 | ); 121 | mainGroup = BAE10B3C1CBC2A8F009E9EBD; 122 | productRefGroup = BAE10B461CBC2A8F009E9EBD /* Products */; 123 | projectDirPath = ""; 124 | projectRoot = ""; 125 | targets = ( 126 | BAE10B441CBC2A8F009E9EBD /* CCAnimations */, 127 | ); 128 | }; 129 | /* End PBXProject section */ 130 | 131 | /* Begin PBXResourcesBuildPhase section */ 132 | BAE10B431CBC2A8F009E9EBD /* Resources */ = { 133 | isa = PBXResourcesBuildPhase; 134 | buildActionMask = 2147483647; 135 | files = ( 136 | BAE10B531CBC2A8F009E9EBD /* LaunchScreen.storyboard in Resources */, 137 | BAE10B501CBC2A8F009E9EBD /* Assets.xcassets in Resources */, 138 | BAE10B4E1CBC2A8F009E9EBD /* Main.storyboard in Resources */, 139 | ); 140 | runOnlyForDeploymentPostprocessing = 0; 141 | }; 142 | /* End PBXResourcesBuildPhase section */ 143 | 144 | /* Begin PBXSourcesBuildPhase section */ 145 | BAE10B411CBC2A8F009E9EBD /* Sources */ = { 146 | isa = PBXSourcesBuildPhase; 147 | buildActionMask = 2147483647; 148 | files = ( 149 | BAE10B4B1CBC2A8F009E9EBD /* ViewController.swift in Sources */, 150 | BAE10B491CBC2A8F009E9EBD /* AppDelegate.swift in Sources */, 151 | BAE10B641CBC378F009E9EBD /* CCAnimations.swift in Sources */, 152 | ); 153 | runOnlyForDeploymentPostprocessing = 0; 154 | }; 155 | /* End PBXSourcesBuildPhase section */ 156 | 157 | /* Begin PBXVariantGroup section */ 158 | BAE10B4C1CBC2A8F009E9EBD /* Main.storyboard */ = { 159 | isa = PBXVariantGroup; 160 | children = ( 161 | BAE10B4D1CBC2A8F009E9EBD /* Base */, 162 | ); 163 | name = Main.storyboard; 164 | sourceTree = ""; 165 | }; 166 | BAE10B511CBC2A8F009E9EBD /* LaunchScreen.storyboard */ = { 167 | isa = PBXVariantGroup; 168 | children = ( 169 | BAE10B521CBC2A8F009E9EBD /* Base */, 170 | ); 171 | name = LaunchScreen.storyboard; 172 | sourceTree = ""; 173 | }; 174 | /* End PBXVariantGroup section */ 175 | 176 | /* Begin XCBuildConfiguration section */ 177 | BAE10B551CBC2A8F009E9EBD /* Debug */ = { 178 | isa = XCBuildConfiguration; 179 | buildSettings = { 180 | ALWAYS_SEARCH_USER_PATHS = NO; 181 | CLANG_ANALYZER_NONNULL = YES; 182 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 183 | CLANG_CXX_LIBRARY = "libc++"; 184 | CLANG_ENABLE_MODULES = YES; 185 | CLANG_ENABLE_OBJC_ARC = YES; 186 | CLANG_WARN_BOOL_CONVERSION = YES; 187 | CLANG_WARN_CONSTANT_CONVERSION = YES; 188 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 189 | CLANG_WARN_EMPTY_BODY = YES; 190 | CLANG_WARN_ENUM_CONVERSION = YES; 191 | CLANG_WARN_INT_CONVERSION = YES; 192 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 193 | CLANG_WARN_UNREACHABLE_CODE = YES; 194 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 195 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 196 | COPY_PHASE_STRIP = NO; 197 | DEBUG_INFORMATION_FORMAT = dwarf; 198 | ENABLE_STRICT_OBJC_MSGSEND = YES; 199 | ENABLE_TESTABILITY = YES; 200 | GCC_C_LANGUAGE_STANDARD = gnu99; 201 | GCC_DYNAMIC_NO_PIC = NO; 202 | GCC_NO_COMMON_BLOCKS = YES; 203 | GCC_OPTIMIZATION_LEVEL = 0; 204 | GCC_PREPROCESSOR_DEFINITIONS = ( 205 | "DEBUG=1", 206 | "$(inherited)", 207 | ); 208 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 209 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 210 | GCC_WARN_UNDECLARED_SELECTOR = YES; 211 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 212 | GCC_WARN_UNUSED_FUNCTION = YES; 213 | GCC_WARN_UNUSED_VARIABLE = YES; 214 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 215 | MTL_ENABLE_DEBUG_INFO = YES; 216 | ONLY_ACTIVE_ARCH = YES; 217 | SDKROOT = iphoneos; 218 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 219 | TARGETED_DEVICE_FAMILY = "1,2"; 220 | }; 221 | name = Debug; 222 | }; 223 | BAE10B561CBC2A8F009E9EBD /* Release */ = { 224 | isa = XCBuildConfiguration; 225 | buildSettings = { 226 | ALWAYS_SEARCH_USER_PATHS = NO; 227 | CLANG_ANALYZER_NONNULL = YES; 228 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 229 | CLANG_CXX_LIBRARY = "libc++"; 230 | CLANG_ENABLE_MODULES = YES; 231 | CLANG_ENABLE_OBJC_ARC = YES; 232 | CLANG_WARN_BOOL_CONVERSION = YES; 233 | CLANG_WARN_CONSTANT_CONVERSION = YES; 234 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 235 | CLANG_WARN_EMPTY_BODY = YES; 236 | CLANG_WARN_ENUM_CONVERSION = YES; 237 | CLANG_WARN_INT_CONVERSION = YES; 238 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 239 | CLANG_WARN_UNREACHABLE_CODE = YES; 240 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 241 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 242 | COPY_PHASE_STRIP = NO; 243 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 244 | ENABLE_NS_ASSERTIONS = NO; 245 | ENABLE_STRICT_OBJC_MSGSEND = YES; 246 | GCC_C_LANGUAGE_STANDARD = gnu99; 247 | GCC_NO_COMMON_BLOCKS = YES; 248 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 249 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 250 | GCC_WARN_UNDECLARED_SELECTOR = YES; 251 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 252 | GCC_WARN_UNUSED_FUNCTION = YES; 253 | GCC_WARN_UNUSED_VARIABLE = YES; 254 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 255 | MTL_ENABLE_DEBUG_INFO = NO; 256 | SDKROOT = iphoneos; 257 | TARGETED_DEVICE_FAMILY = "1,2"; 258 | VALIDATE_PRODUCT = YES; 259 | }; 260 | name = Release; 261 | }; 262 | BAE10B581CBC2A8F009E9EBD /* Debug */ = { 263 | isa = XCBuildConfiguration; 264 | buildSettings = { 265 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 266 | INFOPLIST_FILE = CCAnimations/Info.plist; 267 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 268 | PRODUCT_BUNDLE_IDENTIFIER = com.CCAnimations; 269 | PRODUCT_NAME = "$(TARGET_NAME)"; 270 | }; 271 | name = Debug; 272 | }; 273 | BAE10B591CBC2A8F009E9EBD /* Release */ = { 274 | isa = XCBuildConfiguration; 275 | buildSettings = { 276 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 277 | INFOPLIST_FILE = CCAnimations/Info.plist; 278 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 279 | PRODUCT_BUNDLE_IDENTIFIER = com.CCAnimations; 280 | PRODUCT_NAME = "$(TARGET_NAME)"; 281 | }; 282 | name = Release; 283 | }; 284 | /* End XCBuildConfiguration section */ 285 | 286 | /* Begin XCConfigurationList section */ 287 | BAE10B401CBC2A8F009E9EBD /* Build configuration list for PBXProject "CCAnimations" */ = { 288 | isa = XCConfigurationList; 289 | buildConfigurations = ( 290 | BAE10B551CBC2A8F009E9EBD /* Debug */, 291 | BAE10B561CBC2A8F009E9EBD /* Release */, 292 | ); 293 | defaultConfigurationIsVisible = 0; 294 | defaultConfigurationName = Release; 295 | }; 296 | BAE10B571CBC2A8F009E9EBD /* Build configuration list for PBXNativeTarget "CCAnimations" */ = { 297 | isa = XCConfigurationList; 298 | buildConfigurations = ( 299 | BAE10B581CBC2A8F009E9EBD /* Debug */, 300 | BAE10B591CBC2A8F009E9EBD /* Release */, 301 | ); 302 | defaultConfigurationIsVisible = 0; 303 | defaultConfigurationName = Release; 304 | }; 305 | /* End XCConfigurationList section */ 306 | }; 307 | rootObject = BAE10B3D1CBC2A8F009E9EBD /* Project object */; 308 | } 309 | -------------------------------------------------------------------------------- /CCAnimations/CCAnimations.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CCAnimations/CCAnimations.xcodeproj/xcuserdata/carlos.correa.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /CCAnimations/CCAnimations.xcodeproj/xcuserdata/carlos.correa.xcuserdatad/xcschemes/CCAnimations.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /CCAnimations/CCAnimations.xcodeproj/xcuserdata/carlos.correa.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | CCAnimations.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | BAE10B441CBC2A8F009E9EBD 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /CCAnimations/CCAnimations/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CCAnimations 4 | // 5 | // Created by Carlos Corrêa on 4/11/16. 6 | // Copyright © 2016 Carlos Corrêa. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // 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. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // 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. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // 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. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /CCAnimations/CCAnimations/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "83.5x83.5", 66 | "scale" : "2x" 67 | } 68 | ], 69 | "info" : { 70 | "version" : 1, 71 | "author" : "xcode" 72 | } 73 | } -------------------------------------------------------------------------------- /CCAnimations/CCAnimations/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /CCAnimations/CCAnimations/Assets.xcassets/heman.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "heman.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /CCAnimations/CCAnimations/Assets.xcassets/heman.imageset/heman.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caiobzen/CCAnimations/dc3dfda426697986cc4bf8accacf238a76f4963c/CCAnimations/CCAnimations/Assets.xcassets/heman.imageset/heman.jpg -------------------------------------------------------------------------------- /CCAnimations/CCAnimations/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 | -------------------------------------------------------------------------------- /CCAnimations/CCAnimations/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /CCAnimations/CCAnimations/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 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UIStatusBarHidden 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | UISupportedInterfaceOrientations~ipad 42 | 43 | UIInterfaceOrientationPortrait 44 | UIInterfaceOrientationPortraitUpsideDown 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /CCAnimations/CCAnimations/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // CCAnimations 4 | // 5 | // Created by Carlos Corrêa on 4/11/16. 6 | // Copyright © 2016 Carlos Corrêa. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | @IBOutlet weak var imgView: UIImageView! 14 | @IBOutlet weak var animationsSegment: UISegmentedControl! 15 | 16 | @IBOutlet weak var animateButton: UIButton! 17 | @IBOutlet weak var animationTitle: UILabel! 18 | override func viewDidLoad() { 19 | super.viewDidLoad() 20 | imgView.layer.cornerRadius = CGRectGetWidth(imgView.frame) / 2 21 | animateButton.layer.cornerRadius = 3.0 22 | animationTitle.text = "CCAnimationPop()" 23 | } 24 | 25 | @IBAction func animateButtonTouched(sender: AnyObject) { 26 | switch animationsSegment.selectedSegmentIndex { 27 | case 0: 28 | imgView.CCAnimationPop() 29 | case 1: 30 | imgView.CCAnimationShake() 31 | case 2: 32 | imgView.CCAnimationRotate() 33 | case 3: 34 | imgView.CCAnimation3DxRotation() 35 | case 4: 36 | imgView.CCAnimation3DyRotation() 37 | case 5: 38 | imgView.CCAnimationJump(intensity: 50) 39 | case 6: 40 | imgView.CCAnimationFadeUp(3.0, intensity: 200) 41 | case 7: 42 | imgView.CCAnimationFadeDown(3.0, intensity: 200) 43 | case 8: 44 | imgView.CCAnimationFadeToLeft(3.0, intensity: 200) 45 | case 9: 46 | imgView.CCAnimationFadeToRight(3.0, intensity: 200) 47 | case 10: 48 | imgView.CCAnimationJumpTwistY(intensity: 100) 49 | case 11: 50 | imgView.CCAnimationJumpTwistX(intensity: 100) 51 | default: 52 | break 53 | } 54 | } 55 | 56 | @IBAction func segmentDidChanged(sender: AnyObject) { 57 | switch animationsSegment.selectedSegmentIndex { 58 | case 0: 59 | animationTitle.text = "CCAnimationPop()" 60 | case 1: 61 | animationTitle.text = "CCAnimationShake()" 62 | case 2: 63 | animationTitle.text = "CCAnimationRotate()" 64 | case 3: 65 | animationTitle.text = "CCAnimation3DxRotation()" 66 | case 4: 67 | animationTitle.text = "CCAnimation3DyRotation()" 68 | case 5: 69 | animationTitle.text = "CCAnimationJump()" 70 | case 6: 71 | animationTitle.text = "CCAnimationFadeUp()" 72 | case 7: 73 | animationTitle.text = "CCAnimationFadeDown()" 74 | case 8: 75 | animationTitle.text = "CCAnimationFadeToLeft()" 76 | case 9: 77 | animationTitle.text = "CCAnimationFadeToRight()" 78 | case 10: 79 | animationTitle.text = "CCAnimationJumpTwistY()" 80 | case 11: 81 | animationTitle.text = "CCAnimationJumpTwistX()" 82 | default: 83 | break 84 | } 85 | } 86 | } 87 | 88 | -------------------------------------------------------------------------------- /CCAnimations/demo/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caiobzen/CCAnimations/dc3dfda426697986cc4bf8accacf238a76f4963c/CCAnimations/demo/1.gif -------------------------------------------------------------------------------- /CCAnimations/demo/10.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caiobzen/CCAnimations/dc3dfda426697986cc4bf8accacf238a76f4963c/CCAnimations/demo/10.gif -------------------------------------------------------------------------------- /CCAnimations/demo/11.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caiobzen/CCAnimations/dc3dfda426697986cc4bf8accacf238a76f4963c/CCAnimations/demo/11.gif -------------------------------------------------------------------------------- /CCAnimations/demo/12.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caiobzen/CCAnimations/dc3dfda426697986cc4bf8accacf238a76f4963c/CCAnimations/demo/12.gif -------------------------------------------------------------------------------- /CCAnimations/demo/2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caiobzen/CCAnimations/dc3dfda426697986cc4bf8accacf238a76f4963c/CCAnimations/demo/2.gif -------------------------------------------------------------------------------- /CCAnimations/demo/3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caiobzen/CCAnimations/dc3dfda426697986cc4bf8accacf238a76f4963c/CCAnimations/demo/3.gif -------------------------------------------------------------------------------- /CCAnimations/demo/4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caiobzen/CCAnimations/dc3dfda426697986cc4bf8accacf238a76f4963c/CCAnimations/demo/4.gif -------------------------------------------------------------------------------- /CCAnimations/demo/5.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caiobzen/CCAnimations/dc3dfda426697986cc4bf8accacf238a76f4963c/CCAnimations/demo/5.gif -------------------------------------------------------------------------------- /CCAnimations/demo/6.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caiobzen/CCAnimations/dc3dfda426697986cc4bf8accacf238a76f4963c/CCAnimations/demo/6.gif -------------------------------------------------------------------------------- /CCAnimations/demo/7.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caiobzen/CCAnimations/dc3dfda426697986cc4bf8accacf238a76f4963c/CCAnimations/demo/7.gif -------------------------------------------------------------------------------- /CCAnimations/demo/8.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caiobzen/CCAnimations/dc3dfda426697986cc4bf8accacf238a76f4963c/CCAnimations/demo/8.gif -------------------------------------------------------------------------------- /CCAnimations/demo/9.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caiobzen/CCAnimations/dc3dfda426697986cc4bf8accacf238a76f4963c/CCAnimations/demo/9.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Carlos Corrêa da Silva 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 | # CCAnimations 2 | 3 | [![Version](https://img.shields.io/cocoapods/v/CCAnimations.svg?style=flat)](http://cocoapods.org/pods/CCAnimations) 4 | [![License](https://img.shields.io/cocoapods/l/CCAnimations.svg?style=flat)](http://cocoapods.org/pods/CCAnimations) 5 | [![Platform](https://img.shields.io/cocoapods/p/CCAnimations.svg?style=flat)](http://cocoapods.org/pods/CCAnimations) 6 | 7 | CCAnimations is a simple set of custom CAAnimations, handcrafted by me. I love to add animations in my apps, and everytime that I want to do that, I had to search through my apps for sample animation codes. Not anymore! Now I will focus on adding new animations as needed. 8 | Feel free to contribute with your own animations and feedbacks! :+1: 9 | 10 |
11 | ## Installation 💻 12 | 13 | ####CocoaPods 14 | You can Install CCAnimations through [CocoaPods](https://cocoapods.org/pods/CCAnimations). In order to do this, add the following line to your Podfile: 15 | 16 | `pod "CCAnimations"` 17 | 18 |
19 | 20 | ####Manually 21 | Simply clone the repository (or even [download](https://github.com/caiobzen/CCAnimations/archive/master.zip) it) and add the file named `CCAnimations.swift` into your XCode project. 22 | 23 |

24 | ## Usage 25 | 26 | In order to use any of those animations, you just need to pick an UIView object and call a CCAnimation as the following example: 27 | ```swift 28 | myImgView.CCAnimationPop() 29 | myLabel.CCAnimationRotate() 30 | ``` 31 | You can also specify some parameters, in order to create even more customizable animations: 32 | ```swift 33 | myImgView.CCAnimationJump(intensity: 50) 34 | myImgView.CCAnimationPop(0.9) // This will shrink the view, instead of making it bigger. 35 | ``` 36 | 37 | You can also mix animations, like the `CCAnimationJumpTwistX` that does both jump and 3DxRotation 38 | 39 | For now, there are 12 custom animations: 40 | 41 | ##### ▶️ CCAnimationPop() 42 | 43 | Demo 44 | 45 |
46 | ##### ▶️ CCAnimationShake() 47 | 48 | Demo 49 | 50 |
51 | ##### ▶️ CCAnimationRotate() 52 | 53 | Demo 54 | 55 |
56 | ##### ▶️ CCAnimation3DxRotation() 57 | 58 | Demo 59 | 60 |
61 | ##### ▶️ CCAnimation3DyRotation() 62 | 63 | Demo 64 | 65 |
66 | ##### ▶️ CCAnimationJump() 67 | 68 | Demo 69 | 70 |
71 | ##### ▶️ CCAnimationFadeUp() 72 | 73 | Demo 74 | 75 |
76 | ##### ▶️ CCAnimationFadeDown() 77 | 78 | Demo 79 | 80 |
81 | ##### ▶️ CCAnimationFadeToLeft() 82 | 83 | Demo 84 | 85 |
86 | ##### ▶️ CCAnimationFadeToRight() 87 | 88 | Demo 89 | 90 |
91 | ##### ▶️ CCAnimationJumpTwistY() 92 | 93 | Demo 94 | 95 |
96 | ##### ▶️ CCAnimationJumpTwistX() 97 | 98 | Demo 99 | 100 | 101 | 102 | ## 📜 License 103 | 104 | CCAnimations is available under the MIT license. Please read the LICENSE file for more info if needed. 105 | -------------------------------------------------------------------------------- /Source/CCAnimations.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CCAnimations.swift 3 | // PopAnimation 4 | // 5 | // Created by Carlos Corrêa on 10/04/16. 6 | // Copyright © 2016 Carlos Corrêa. All rights reserved. 7 | // 8 | 9 | 10 | 11 | import UIKit 12 | 13 | enum AnimationKeyPath:String { 14 | case 15 | scale = "transform.scale", 16 | zRotation = "transform.rotation.z", 17 | xPosition = "position.x", 18 | yPosition = "position.y", 19 | xTranslation = "translation.x", 20 | transform = "transform", 21 | opacity = "opacity" 22 | } 23 | 24 | enum Axis { 25 | case 26 | x, 27 | y, 28 | z 29 | } 30 | 31 | enum Side { 32 | case 33 | Up, 34 | Down, 35 | Left, 36 | Right 37 | } 38 | 39 | // MARK: helpers 40 | 41 | func degreeToRadians(angle:Float) -> Float { 42 | return (angle / 180 * Float(M_PI)) 43 | } 44 | 45 | extension UIView { 46 | 47 | // MARK: - Setup Animation functions 48 | 49 | private func setupBasicAnimation(animation:CABasicAnimation, 50 | duration:CFTimeInterval, 51 | fromValue:AnyObject? = nil, 52 | toValue:AnyObject? = nil, 53 | byValue:AnyObject? = nil, 54 | cumulative: Bool = false, 55 | reverse: Bool = false, 56 | repeatCount:Float = 0, 57 | fillMode:String = kCAFilterLinear, 58 | removedOnCompletion:Bool = true) { 59 | 60 | animation.duration = duration 61 | animation.cumulative = cumulative 62 | animation.repeatCount = repeatCount 63 | animation.fromValue = fromValue 64 | animation.toValue = toValue 65 | animation.byValue = byValue 66 | animation.autoreverses = reverse 67 | animation.fillMode = fillMode 68 | animation.removedOnCompletion = removedOnCompletion 69 | } 70 | 71 | private func setupKeyFrameAnimation(animation:CAKeyframeAnimation, 72 | values:[AnyObject]?, 73 | keyTimes:[AnyObject]?, 74 | duration:CFTimeInterval) { 75 | animation.values = values 76 | animation.keyTimes = keyTimes as? [NSNumber] ?? [] 77 | animation.duration = duration 78 | } 79 | 80 | private func setupSpringAnimation(animation:CASpringAnimation, 81 | damping:CGFloat = 1.0, 82 | initialVelocity:CGFloat = 1.0, 83 | speed:Float = 1.0) { 84 | animation.damping = damping 85 | animation.initialVelocity = initialVelocity 86 | animation.speed = speed 87 | } 88 | 89 | private func runAnimation(animation:CAAnimation) { 90 | self.layer.addAnimation(animation, forKey: nil) 91 | } 92 | 93 | // MARK: - Factory 94 | 95 | private func newAnimation(type:T.Type, keyPath:AnimationKeyPath) -> T { 96 | if type == CABasicAnimation.self { 97 | return basicAnimation(keyPath: keyPath) as! T 98 | } else if type == CAKeyframeAnimation.self { 99 | return keyFrameAnimation(keyPath: keyPath) as! T 100 | } else if type == CASpringAnimation.self { 101 | return springAnimation(keyPath: keyPath) as! T 102 | } 103 | return CAAnimation() as! T 104 | } 105 | 106 | private func basicAnimation(keyPath keyPath: AnimationKeyPath) -> CABasicAnimation { 107 | return CABasicAnimation(keyPath: keyPath.rawValue) 108 | } 109 | 110 | private func keyFrameAnimation(keyPath keyPath: AnimationKeyPath) -> CAKeyframeAnimation { 111 | return CAKeyframeAnimation(keyPath: keyPath.rawValue) 112 | } 113 | 114 | private func springAnimation(keyPath keyPath: AnimationKeyPath) -> CASpringAnimation { 115 | return CASpringAnimation(keyPath: keyPath.rawValue) 116 | } 117 | 118 | // MARK: - Animation Helpers 119 | 120 | private func scaleAnimation(size:CGFloat, duration:CFTimeInterval) { 121 | let animation = newAnimation(CASpringAnimation.self, keyPath: .scale) 122 | setupBasicAnimation(animation, duration: duration, toValue:size, reverse:true) 123 | setupSpringAnimation(animation, damping: 7.0, initialVelocity: 1.1, speed: 1.7) 124 | runAnimation(animation) 125 | } 126 | 127 | private func shakeAnimation(duration:CFTimeInterval) { 128 | let centerPoint = self.center 129 | let animationValues = [centerPoint.x, centerPoint.x + 5, centerPoint.x - 5, centerPoint.x + 5, centerPoint.x] 130 | let keyTimes = [0, 0.25, 0.75, 1.25, 1] 131 | let animation = newAnimation(CAKeyframeAnimation.self, keyPath: .xPosition) 132 | setupKeyFrameAnimation(animation, values: animationValues, keyTimes: keyTimes, duration: duration) 133 | runAnimation(animation) 134 | } 135 | 136 | private func rotate360(repeatCount repeatCount:Float, duration:CFTimeInterval) { 137 | let animation = newAnimation(CABasicAnimation.self, keyPath: .zRotation) 138 | let repeatCount = repeatCount == 0 ? Float(CGFloat.max) : repeatCount 139 | setupBasicAnimation(animation, duration:duration, toValue:(M_PI * 2.0), repeatCount:repeatCount) 140 | runAnimation(animation) 141 | } 142 | 143 | private func jumpWithIntensity(withIntensity intensity:CGFloat, duration:CFTimeInterval) { 144 | let currentPoint = self.center 145 | let fromValue = currentPoint.y 146 | let toValue = fromValue - intensity 147 | let animation = newAnimation(CASpringAnimation.self, keyPath: .yPosition) 148 | setupBasicAnimation(animation, duration: duration, toValue:toValue, reverse:true) 149 | setupSpringAnimation(animation, damping: 8.2, initialVelocity: 1.2, speed: 1.1) 150 | runAnimation(animation) 151 | } 152 | 153 | private func rotate3DWithAxis(axis:Axis, withDuration duration:CFTimeInterval) { 154 | var transform3D:CATransform3D 155 | 156 | if axis == .x { 157 | transform3D = CATransform3DRotate(self.layer.transform, CGFloat(degreeToRadians(180)), 0.0, 1.0, 0.0) 158 | } else { 159 | transform3D = CATransform3DRotate(self.layer.transform, CGFloat(degreeToRadians(180)), 1.0, 0.0, 0.0) 160 | } 161 | 162 | let animation = newAnimation(CABasicAnimation.self, keyPath: .transform) 163 | setupBasicAnimation(animation, duration: duration, toValue: NSValue(CATransform3D:transform3D), fillMode:kCAFillModeForwards, removedOnCompletion:false, repeatCount:2, cumulative:true) 164 | runAnimation(animation) 165 | } 166 | 167 | private func moveSideways(WithDuration duration:CFTimeInterval, side:Side, value:CGFloat) { 168 | let keyPath:AnimationKeyPath 169 | var toValue:CGFloat = 0.0 170 | switch side { 171 | case .Up, 172 | .Down: 173 | keyPath = .yPosition 174 | toValue = self.center.y 175 | break 176 | case .Left, 177 | .Right: 178 | keyPath = .xPosition 179 | toValue = self.center.x 180 | break 181 | } 182 | 183 | if (side == .Left || side == .Up) { 184 | toValue -= value 185 | } else { 186 | toValue += value 187 | } 188 | 189 | let animation = newAnimation(CABasicAnimation.self, keyPath: keyPath) 190 | setupBasicAnimation(animation, duration: duration, toValue:toValue) 191 | runAnimation(animation) 192 | } 193 | 194 | private func alphaAnimation(withDuration duration:CFTimeInterval, withAlpha alpha:CGFloat) { 195 | let animation = newAnimation(CABasicAnimation.self, keyPath: .opacity) 196 | setupBasicAnimation(animation, duration: duration, toValue:alpha) 197 | runAnimation(animation) 198 | } 199 | 200 | 201 | // MARK: - Custom animations 202 | 203 | /** 204 | This will create a pop animation by growing or shrinking the view scale size and then going back to the original state 205 | 206 | - parameter duration: The duration of the animation 207 | - parameter scale: The scale size that the view will resize to (1.0 is the original scale) 208 | */ 209 | func CCAnimationPop(duration:CFTimeInterval = 0.3, scale:CGFloat = 1.05) { 210 | scaleAnimation(scale, duration: duration) 211 | } 212 | 213 | /** 214 | This will create a shake animation by moving the view x position to the left and right 215 | 216 | - parameter duration: The duration of the animation 217 | */ 218 | func CCAnimationShake(duration:CFTimeInterval = 0.4) { 219 | shakeAnimation(duration) 220 | } 221 | 222 | /** 223 | This will create a 360 degrees rotation animation 224 | 225 | - parameter duration: The duration of the animation 226 | - parameter repeatCount: The number of times that the animation will repeat. 0 stands for infinite. 227 | */ 228 | func CCAnimationRotate(duration:CFTimeInterval = 0.4, repeatCount:Float = 1) { 229 | rotate360(repeatCount: repeatCount, duration: duration) 230 | } 231 | 232 | /** 233 | This will create a jump-like animation, by changing the Y position. 234 | 235 | - parameter duration: The animation duration 236 | - parameter intensity: how much the view will be moved in the Y axis. 237 | */ 238 | func CCAnimationJump(duration:CFTimeInterval = 0.3, intensity:CGFloat) { 239 | jumpWithIntensity(withIntensity: intensity, duration: duration) 240 | } 241 | 242 | /** 243 | This will create a X axis rotation animation by 360 degrees. 244 | 245 | - parameter duration: The animation duration 246 | */ 247 | func CCAnimation3DxRotation(duration:CFTimeInterval = 0.4) { 248 | rotate3DWithAxis(.x, withDuration: duration) 249 | } 250 | 251 | /** 252 | This will create a Y axis rotation animation by 360 degrees. 253 | 254 | - parameter duration: The animation duration 255 | */ 256 | func CCAnimation3DyRotation(duration:CFTimeInterval = 0.4) { 257 | rotate3DWithAxis(.y, withDuration: duration) 258 | } 259 | 260 | /** 261 | This will create a jump and spin on X axis animation. It's a union of CCAnimationJump and CCJumpTwistXAnimation 262 | 263 | - parameter duration: The animation duration 264 | - parameter intensity: how much the view will be moved in the Y axis. 265 | */ 266 | func CCAnimationJumpTwistX(duration:CFTimeInterval = 0.4, intensity:CGFloat) { 267 | CCAnimationJump(duration, intensity: intensity) 268 | CCAnimation3DxRotation(duration) 269 | } 270 | 271 | /** 272 | This will create a jump and spin on Y axis animation. It's a union of CCAnimationJump and CCJumpTwistYAnimation 273 | 274 | - parameter duration: The animation duration 275 | - parameter intensity: how much the view will be moved in the Y axis. 276 | */ 277 | func CCAnimationJumpTwistY(duration:CFTimeInterval = 0.4, intensity:CGFloat) { 278 | CCAnimationJump(duration, intensity: intensity) 279 | CCAnimation3DyRotation(duration) 280 | } 281 | 282 | /** 283 | This will create a fade animation while moving the view to the left. 284 | 285 | - parameter duration: The animation duration 286 | - parameter intensity: how much the view will be moved to the left. 287 | */ 288 | func CCAnimationFadeToLeft(duration:CFTimeInterval = 0.4, intensity:CGFloat) { 289 | moveSideways(WithDuration: duration, side: .Left, value: intensity) 290 | alphaAnimation(withDuration: duration, withAlpha: 0) 291 | } 292 | 293 | /** 294 | This will create a fade animation while moving the view to the right. 295 | 296 | - parameter duration: The animation duration 297 | - parameter intensity: how much the view will be moved to the tight. 298 | */ 299 | func CCAnimationFadeToRight(duration:CFTimeInterval = 0.4, intensity:CGFloat) { 300 | moveSideways(WithDuration: duration, side: .Right, value: intensity) 301 | alphaAnimation(withDuration: duration, withAlpha: 0) 302 | } 303 | 304 | /** 305 | This will create a fade animation while moving the view to the top of the screen. 306 | 307 | - parameter duration: The animation duration 308 | - parameter intensity: how much the view will be moved to the top of the screen. 309 | */ 310 | func CCAnimationFadeUp(duration:CFTimeInterval = 0.4, intensity:CGFloat) { 311 | moveSideways(WithDuration: duration, side: .Up, value: intensity) 312 | alphaAnimation(withDuration: duration, withAlpha: 0) 313 | } 314 | 315 | /** 316 | This will create a fade animation while moving the view to the bottom of the screen. 317 | 318 | - parameter duration: The animation duration 319 | - parameter intensity: how much the view will be moved to the bottom of the screen. 320 | */ 321 | func CCAnimationFadeDown(duration:CFTimeInterval = 0.4, intensity:CGFloat) { 322 | moveSideways(WithDuration: duration, side: .Down, value: intensity) 323 | alphaAnimation(withDuration: duration, withAlpha: 0) 324 | } 325 | } 326 | --------------------------------------------------------------------------------