├── README.md ├── ShoppingCartAnimation.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── caiqiang.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── caiqiang.xcuserdatad │ └── xcschemes │ ├── ShoppingCartAnimation.xcscheme │ └── xcschememanagement.plist └── ShoppingCartAnimation ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist ├── ShoppingCartTool.h ├── ShoppingCartTool.m ├── ViewController.h ├── ViewController.m ├── cart.png ├── heheda.png └── main.m /README.md: -------------------------------------------------------------------------------- 1 | ### 仿京东的加入购物车动画 2 | 3 | ![😅.gif](http://upload-images.jianshu.io/upload_images/1692043-b5c7926b9b6fdb8b.gif?imageMogr2/auto-orient/strip) 4 | -------------------------------------------------------------------------------- /ShoppingCartAnimation.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | D92224251F1C99DB00F65998 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D92224241F1C99DB00F65998 /* main.m */; }; 11 | D92224281F1C99DB00F65998 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D92224271F1C99DB00F65998 /* AppDelegate.m */; }; 12 | D922242B1F1C99DB00F65998 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D922242A1F1C99DB00F65998 /* ViewController.m */; }; 13 | D922242E1F1C99DB00F65998 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D922242C1F1C99DB00F65998 /* Main.storyboard */; }; 14 | D92224301F1C99DB00F65998 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D922242F1F1C99DB00F65998 /* Assets.xcassets */; }; 15 | D92224331F1C99DB00F65998 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D92224311F1C99DB00F65998 /* LaunchScreen.storyboard */; }; 16 | D922243C1F1C9A2A00F65998 /* ShoppingCartTool.m in Sources */ = {isa = PBXBuildFile; fileRef = D922243B1F1C9A2A00F65998 /* ShoppingCartTool.m */; }; 17 | D97EFED11F1DA0FB0073976D /* heheda.png in Resources */ = {isa = PBXBuildFile; fileRef = D97EFED01F1DA0FB0073976D /* heheda.png */; }; 18 | D97EFED31F1DA2F10073976D /* cart.png in Resources */ = {isa = PBXBuildFile; fileRef = D97EFED21F1DA2F10073976D /* cart.png */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | D92224201F1C99DB00F65998 /* ShoppingCartAnimation.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ShoppingCartAnimation.app; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | D92224241F1C99DB00F65998 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 24 | D92224261F1C99DB00F65998 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 25 | D92224271F1C99DB00F65998 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 26 | D92224291F1C99DB00F65998 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 27 | D922242A1F1C99DB00F65998 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 28 | D922242D1F1C99DB00F65998 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 29 | D922242F1F1C99DB00F65998 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 30 | D92224321F1C99DB00F65998 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 31 | D92224341F1C99DB00F65998 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | D922243A1F1C9A2A00F65998 /* ShoppingCartTool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShoppingCartTool.h; sourceTree = ""; }; 33 | D922243B1F1C9A2A00F65998 /* ShoppingCartTool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShoppingCartTool.m; sourceTree = ""; }; 34 | D97EFED01F1DA0FB0073976D /* heheda.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = heheda.png; sourceTree = ""; }; 35 | D97EFED21F1DA2F10073976D /* cart.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = cart.png; sourceTree = ""; }; 36 | /* End PBXFileReference section */ 37 | 38 | /* Begin PBXFrameworksBuildPhase section */ 39 | D922241D1F1C99DB00F65998 /* Frameworks */ = { 40 | isa = PBXFrameworksBuildPhase; 41 | buildActionMask = 2147483647; 42 | files = ( 43 | ); 44 | runOnlyForDeploymentPostprocessing = 0; 45 | }; 46 | /* End PBXFrameworksBuildPhase section */ 47 | 48 | /* Begin PBXGroup section */ 49 | D92224171F1C99DB00F65998 = { 50 | isa = PBXGroup; 51 | children = ( 52 | D92224221F1C99DB00F65998 /* ShoppingCartAnimation */, 53 | D92224211F1C99DB00F65998 /* Products */, 54 | ); 55 | sourceTree = ""; 56 | }; 57 | D92224211F1C99DB00F65998 /* Products */ = { 58 | isa = PBXGroup; 59 | children = ( 60 | D92224201F1C99DB00F65998 /* ShoppingCartAnimation.app */, 61 | ); 62 | name = Products; 63 | sourceTree = ""; 64 | }; 65 | D92224221F1C99DB00F65998 /* ShoppingCartAnimation */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | D92224261F1C99DB00F65998 /* AppDelegate.h */, 69 | D92224271F1C99DB00F65998 /* AppDelegate.m */, 70 | D92224291F1C99DB00F65998 /* ViewController.h */, 71 | D922242A1F1C99DB00F65998 /* ViewController.m */, 72 | D97EFED01F1DA0FB0073976D /* heheda.png */, 73 | D97EFED21F1DA2F10073976D /* cart.png */, 74 | D922242C1F1C99DB00F65998 /* Main.storyboard */, 75 | D922242F1F1C99DB00F65998 /* Assets.xcassets */, 76 | D92224311F1C99DB00F65998 /* LaunchScreen.storyboard */, 77 | D92224341F1C99DB00F65998 /* Info.plist */, 78 | D92224231F1C99DB00F65998 /* Supporting Files */, 79 | D922243A1F1C9A2A00F65998 /* ShoppingCartTool.h */, 80 | D922243B1F1C9A2A00F65998 /* ShoppingCartTool.m */, 81 | ); 82 | path = ShoppingCartAnimation; 83 | sourceTree = ""; 84 | }; 85 | D92224231F1C99DB00F65998 /* Supporting Files */ = { 86 | isa = PBXGroup; 87 | children = ( 88 | D92224241F1C99DB00F65998 /* main.m */, 89 | ); 90 | name = "Supporting Files"; 91 | sourceTree = ""; 92 | }; 93 | /* End PBXGroup section */ 94 | 95 | /* Begin PBXNativeTarget section */ 96 | D922241F1F1C99DB00F65998 /* ShoppingCartAnimation */ = { 97 | isa = PBXNativeTarget; 98 | buildConfigurationList = D92224371F1C99DB00F65998 /* Build configuration list for PBXNativeTarget "ShoppingCartAnimation" */; 99 | buildPhases = ( 100 | D922241C1F1C99DB00F65998 /* Sources */, 101 | D922241D1F1C99DB00F65998 /* Frameworks */, 102 | D922241E1F1C99DB00F65998 /* Resources */, 103 | ); 104 | buildRules = ( 105 | ); 106 | dependencies = ( 107 | ); 108 | name = ShoppingCartAnimation; 109 | productName = ShoppingCartAnimation; 110 | productReference = D92224201F1C99DB00F65998 /* ShoppingCartAnimation.app */; 111 | productType = "com.apple.product-type.application"; 112 | }; 113 | /* End PBXNativeTarget section */ 114 | 115 | /* Begin PBXProject section */ 116 | D92224181F1C99DB00F65998 /* Project object */ = { 117 | isa = PBXProject; 118 | attributes = { 119 | LastUpgradeCheck = 0820; 120 | ORGANIZATIONNAME = kuaijiankang; 121 | TargetAttributes = { 122 | D922241F1F1C99DB00F65998 = { 123 | CreatedOnToolsVersion = 8.2; 124 | ProvisioningStyle = Manual; 125 | }; 126 | }; 127 | }; 128 | buildConfigurationList = D922241B1F1C99DB00F65998 /* Build configuration list for PBXProject "ShoppingCartAnimation" */; 129 | compatibilityVersion = "Xcode 3.2"; 130 | developmentRegion = English; 131 | hasScannedForEncodings = 0; 132 | knownRegions = ( 133 | en, 134 | Base, 135 | ); 136 | mainGroup = D92224171F1C99DB00F65998; 137 | productRefGroup = D92224211F1C99DB00F65998 /* Products */; 138 | projectDirPath = ""; 139 | projectRoot = ""; 140 | targets = ( 141 | D922241F1F1C99DB00F65998 /* ShoppingCartAnimation */, 142 | ); 143 | }; 144 | /* End PBXProject section */ 145 | 146 | /* Begin PBXResourcesBuildPhase section */ 147 | D922241E1F1C99DB00F65998 /* Resources */ = { 148 | isa = PBXResourcesBuildPhase; 149 | buildActionMask = 2147483647; 150 | files = ( 151 | D92224331F1C99DB00F65998 /* LaunchScreen.storyboard in Resources */, 152 | D97EFED31F1DA2F10073976D /* cart.png in Resources */, 153 | D97EFED11F1DA0FB0073976D /* heheda.png in Resources */, 154 | D92224301F1C99DB00F65998 /* Assets.xcassets in Resources */, 155 | D922242E1F1C99DB00F65998 /* Main.storyboard in Resources */, 156 | ); 157 | runOnlyForDeploymentPostprocessing = 0; 158 | }; 159 | /* End PBXResourcesBuildPhase section */ 160 | 161 | /* Begin PBXSourcesBuildPhase section */ 162 | D922241C1F1C99DB00F65998 /* Sources */ = { 163 | isa = PBXSourcesBuildPhase; 164 | buildActionMask = 2147483647; 165 | files = ( 166 | D922242B1F1C99DB00F65998 /* ViewController.m in Sources */, 167 | D922243C1F1C9A2A00F65998 /* ShoppingCartTool.m in Sources */, 168 | D92224281F1C99DB00F65998 /* AppDelegate.m in Sources */, 169 | D92224251F1C99DB00F65998 /* main.m in Sources */, 170 | ); 171 | runOnlyForDeploymentPostprocessing = 0; 172 | }; 173 | /* End PBXSourcesBuildPhase section */ 174 | 175 | /* Begin PBXVariantGroup section */ 176 | D922242C1F1C99DB00F65998 /* Main.storyboard */ = { 177 | isa = PBXVariantGroup; 178 | children = ( 179 | D922242D1F1C99DB00F65998 /* Base */, 180 | ); 181 | name = Main.storyboard; 182 | sourceTree = ""; 183 | }; 184 | D92224311F1C99DB00F65998 /* LaunchScreen.storyboard */ = { 185 | isa = PBXVariantGroup; 186 | children = ( 187 | D92224321F1C99DB00F65998 /* Base */, 188 | ); 189 | name = LaunchScreen.storyboard; 190 | sourceTree = ""; 191 | }; 192 | /* End PBXVariantGroup section */ 193 | 194 | /* Begin XCBuildConfiguration section */ 195 | D92224351F1C99DB00F65998 /* Debug */ = { 196 | isa = XCBuildConfiguration; 197 | buildSettings = { 198 | ALWAYS_SEARCH_USER_PATHS = NO; 199 | CLANG_ANALYZER_NONNULL = YES; 200 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 201 | CLANG_CXX_LIBRARY = "libc++"; 202 | CLANG_ENABLE_MODULES = YES; 203 | CLANG_ENABLE_OBJC_ARC = YES; 204 | CLANG_WARN_BOOL_CONVERSION = YES; 205 | CLANG_WARN_CONSTANT_CONVERSION = YES; 206 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 207 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 208 | CLANG_WARN_EMPTY_BODY = YES; 209 | CLANG_WARN_ENUM_CONVERSION = YES; 210 | CLANG_WARN_INFINITE_RECURSION = YES; 211 | CLANG_WARN_INT_CONVERSION = YES; 212 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 213 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 214 | CLANG_WARN_UNREACHABLE_CODE = YES; 215 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 216 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 217 | COPY_PHASE_STRIP = NO; 218 | DEBUG_INFORMATION_FORMAT = dwarf; 219 | ENABLE_STRICT_OBJC_MSGSEND = YES; 220 | ENABLE_TESTABILITY = YES; 221 | GCC_C_LANGUAGE_STANDARD = gnu99; 222 | GCC_DYNAMIC_NO_PIC = NO; 223 | GCC_NO_COMMON_BLOCKS = YES; 224 | GCC_OPTIMIZATION_LEVEL = 0; 225 | GCC_PREPROCESSOR_DEFINITIONS = ( 226 | "DEBUG=1", 227 | "$(inherited)", 228 | ); 229 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 230 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 231 | GCC_WARN_UNDECLARED_SELECTOR = YES; 232 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 233 | GCC_WARN_UNUSED_FUNCTION = YES; 234 | GCC_WARN_UNUSED_VARIABLE = YES; 235 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 236 | MTL_ENABLE_DEBUG_INFO = YES; 237 | ONLY_ACTIVE_ARCH = YES; 238 | SDKROOT = iphoneos; 239 | TARGETED_DEVICE_FAMILY = "1,2"; 240 | }; 241 | name = Debug; 242 | }; 243 | D92224361F1C99DB00F65998 /* Release */ = { 244 | isa = XCBuildConfiguration; 245 | buildSettings = { 246 | ALWAYS_SEARCH_USER_PATHS = NO; 247 | CLANG_ANALYZER_NONNULL = YES; 248 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 249 | CLANG_CXX_LIBRARY = "libc++"; 250 | CLANG_ENABLE_MODULES = YES; 251 | CLANG_ENABLE_OBJC_ARC = YES; 252 | CLANG_WARN_BOOL_CONVERSION = YES; 253 | CLANG_WARN_CONSTANT_CONVERSION = YES; 254 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 255 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 256 | CLANG_WARN_EMPTY_BODY = YES; 257 | CLANG_WARN_ENUM_CONVERSION = YES; 258 | CLANG_WARN_INFINITE_RECURSION = YES; 259 | CLANG_WARN_INT_CONVERSION = YES; 260 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 261 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 262 | CLANG_WARN_UNREACHABLE_CODE = YES; 263 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 264 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 265 | COPY_PHASE_STRIP = NO; 266 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 267 | ENABLE_NS_ASSERTIONS = NO; 268 | ENABLE_STRICT_OBJC_MSGSEND = YES; 269 | GCC_C_LANGUAGE_STANDARD = gnu99; 270 | GCC_NO_COMMON_BLOCKS = YES; 271 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 272 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 273 | GCC_WARN_UNDECLARED_SELECTOR = YES; 274 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 275 | GCC_WARN_UNUSED_FUNCTION = YES; 276 | GCC_WARN_UNUSED_VARIABLE = YES; 277 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 278 | MTL_ENABLE_DEBUG_INFO = NO; 279 | SDKROOT = iphoneos; 280 | TARGETED_DEVICE_FAMILY = "1,2"; 281 | VALIDATE_PRODUCT = YES; 282 | }; 283 | name = Release; 284 | }; 285 | D92224381F1C99DB00F65998 /* Debug */ = { 286 | isa = XCBuildConfiguration; 287 | buildSettings = { 288 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 289 | DEVELOPMENT_TEAM = ""; 290 | INFOPLIST_FILE = ShoppingCartAnimation/Info.plist; 291 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 292 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 293 | PRODUCT_BUNDLE_IDENTIFIER = KuaiJianKang.ShoppingCartAnimation; 294 | PRODUCT_NAME = "$(TARGET_NAME)"; 295 | }; 296 | name = Debug; 297 | }; 298 | D92224391F1C99DB00F65998 /* Release */ = { 299 | isa = XCBuildConfiguration; 300 | buildSettings = { 301 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 302 | DEVELOPMENT_TEAM = ""; 303 | INFOPLIST_FILE = ShoppingCartAnimation/Info.plist; 304 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 305 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 306 | PRODUCT_BUNDLE_IDENTIFIER = KuaiJianKang.ShoppingCartAnimation; 307 | PRODUCT_NAME = "$(TARGET_NAME)"; 308 | }; 309 | name = Release; 310 | }; 311 | /* End XCBuildConfiguration section */ 312 | 313 | /* Begin XCConfigurationList section */ 314 | D922241B1F1C99DB00F65998 /* Build configuration list for PBXProject "ShoppingCartAnimation" */ = { 315 | isa = XCConfigurationList; 316 | buildConfigurations = ( 317 | D92224351F1C99DB00F65998 /* Debug */, 318 | D92224361F1C99DB00F65998 /* Release */, 319 | ); 320 | defaultConfigurationIsVisible = 0; 321 | defaultConfigurationName = Release; 322 | }; 323 | D92224371F1C99DB00F65998 /* Build configuration list for PBXNativeTarget "ShoppingCartAnimation" */ = { 324 | isa = XCConfigurationList; 325 | buildConfigurations = ( 326 | D92224381F1C99DB00F65998 /* Debug */, 327 | D92224391F1C99DB00F65998 /* Release */, 328 | ); 329 | defaultConfigurationIsVisible = 0; 330 | defaultConfigurationName = Release; 331 | }; 332 | /* End XCConfigurationList section */ 333 | }; 334 | rootObject = D92224181F1C99DB00F65998 /* Project object */; 335 | } 336 | -------------------------------------------------------------------------------- /ShoppingCartAnimation.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ShoppingCartAnimation.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ShoppingCartAnimation.xcodeproj/project.xcworkspace/xcuserdata/caiqiang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CaiWanFeng/ShoppingCartAnimation/a70886743103f1b5f73697b813460893f2512cc5/ShoppingCartAnimation.xcodeproj/project.xcworkspace/xcuserdata/caiqiang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /ShoppingCartAnimation.xcodeproj/xcuserdata/caiqiang.xcuserdatad/xcschemes/ShoppingCartAnimation.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 | -------------------------------------------------------------------------------- /ShoppingCartAnimation.xcodeproj/xcuserdata/caiqiang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ShoppingCartAnimation.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | D922241F1F1C99DB00F65998 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /ShoppingCartAnimation/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // ShoppingCartAnimation 4 | // 5 | // Created by 蔡强 on 2017/7/17. 6 | // Copyright © 2017年 kuaijiankang. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /ShoppingCartAnimation/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // ShoppingCartAnimation 4 | // 5 | // Created by 蔡强 on 2017/7/17. 6 | // Copyright © 2017年 kuaijiankang. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | // test 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // 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. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // 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. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // 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. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // 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. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /ShoppingCartAnimation/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 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /ShoppingCartAnimation/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 | -------------------------------------------------------------------------------- /ShoppingCartAnimation/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 | -------------------------------------------------------------------------------- /ShoppingCartAnimation/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | 购物车动画 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /ShoppingCartAnimation/ShoppingCartTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // ShoppingCartTool.h 3 | // ShoppingCartAnimation 4 | // 5 | // Created by 蔡强 on 2017/7/17. 6 | // Copyright © 2017年 kuaijiankang. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface ShoppingCartTool : NSObject 13 | 14 | /** 15 | 加入购物车的动画效果 16 | 17 | @param goodsImage 商品图片 18 | @param startPoint 动画起点 19 | @param endPoint 动画终点 20 | @param completion 动画执行完成后的回调 21 | */ 22 | + (void)addToShoppingCartWithGoodsImage:(UIImage *)goodsImage 23 | startPoint:(CGPoint)startPoint 24 | endPoint:(CGPoint)endPoint 25 | completion:(void (^)(BOOL finished))completion; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /ShoppingCartAnimation/ShoppingCartTool.m: -------------------------------------------------------------------------------- 1 | // 2 | // ShoppingCartTool.m 3 | // ShoppingCartAnimation 4 | // 5 | // Created by 蔡强 on 2017/7/17. 6 | // Copyright © 2017年 kuaijiankang. All rights reserved. 7 | // 8 | 9 | #import "ShoppingCartTool.h" 10 | 11 | @implementation ShoppingCartTool 12 | 13 | /** 14 | 加入购物车的动画效果 15 | 16 | @param goodsImage 商品图片 17 | @param startPoint 动画起点 18 | @param endPoint 动画终点 19 | @param completion 动画执行完成后的回调 20 | */ 21 | + (void)addToShoppingCartWithGoodsImage:(UIImage *)goodsImage startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint completion:(void (^)(BOOL))completion{ 22 | 23 | //------- 创建shapeLayer -------// 24 | CAShapeLayer *animationLayer = [[CAShapeLayer alloc] init]; 25 | animationLayer.frame = CGRectMake(startPoint.x - 20, startPoint.y - 20, 40, 40); 26 | animationLayer.contents = (id)goodsImage.CGImage; 27 | 28 | // 获取window的最顶层视图控制器 29 | UIViewController *rootVC = [[UIApplication sharedApplication].delegate window].rootViewController; 30 | UIViewController *parentVC = rootVC; 31 | while ((parentVC = rootVC.presentedViewController) != nil ) { 32 | rootVC = parentVC; 33 | } 34 | while ([rootVC isKindOfClass:[UINavigationController class]]) { 35 | rootVC = [(UINavigationController *)rootVC topViewController]; 36 | } 37 | 38 | // 添加layer到顶层视图控制器上 39 | [rootVC.view.layer addSublayer:animationLayer]; 40 | 41 | 42 | //------- 创建移动轨迹 -------// 43 | UIBezierPath *movePath = [UIBezierPath bezierPath]; 44 | [movePath moveToPoint:startPoint]; 45 | [movePath addQuadCurveToPoint:endPoint controlPoint:CGPointMake(200,100)]; 46 | // 轨迹动画 47 | CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 48 | CGFloat durationTime = 1; // 动画时间1秒 49 | pathAnimation.duration = durationTime; 50 | pathAnimation.removedOnCompletion = NO; 51 | pathAnimation.fillMode = kCAFillModeForwards; 52 | pathAnimation.path = movePath.CGPath; 53 | 54 | 55 | //------- 创建缩小动画 -------// 56 | CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; 57 | scaleAnimation.fromValue = [NSNumber numberWithFloat:1.0]; 58 | scaleAnimation.toValue = [NSNumber numberWithFloat:0.5]; 59 | scaleAnimation.duration = 1.0; 60 | scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 61 | scaleAnimation.removedOnCompletion = NO; 62 | scaleAnimation.fillMode = kCAFillModeForwards; 63 | 64 | 65 | // 添加轨迹动画 66 | [animationLayer addAnimation:pathAnimation forKey:nil]; 67 | // 添加缩小动画 68 | [animationLayer addAnimation:scaleAnimation forKey:nil]; 69 | 70 | 71 | //------- 动画结束后执行 -------// 72 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(durationTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 73 | [animationLayer removeFromSuperlayer]; 74 | completion(YES); 75 | }); 76 | } 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /ShoppingCartAnimation/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // ShoppingCartAnimation 4 | // 5 | // Created by 蔡强 on 2017/7/17. 6 | // Copyright © 2017年 kuaijiankang. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /ShoppingCartAnimation/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // ShoppingCartAnimation 4 | // 5 | // Created by 蔡强 on 2017/7/17. 6 | // Copyright © 2017年 kuaijiankang. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "ShoppingCartTool.h" 11 | 12 | @interface ViewController () 13 | 14 | /** 加入购物车按钮 */ 15 | @property (nonatomic, strong) UIButton *addButton; 16 | /** 购物车按钮 */ 17 | @property (nonatomic, strong) UIButton *shoppingCartButton; 18 | /** 商品数量label */ 19 | @property (nonatomic, strong) UILabel *goodsNumLabel; 20 | 21 | @end 22 | 23 | @implementation ViewController 24 | 25 | - (void)viewDidLoad { 26 | [super viewDidLoad]; 27 | // Do any additional setup after loading the view, typically from a nib. 28 | 29 | // UI搭建 30 | [self setUpUI]; 31 | } 32 | 33 | 34 | - (void)setUpUI { 35 | // 加入购物车按钮 36 | self.addButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 120, self.view.frame.size.height - 50, 120, 50)]; 37 | [self.view addSubview:self.addButton]; 38 | self.addButton.backgroundColor = [UIColor redColor]; 39 | [self.addButton setTitle:@"加入购物车" forState:UIControlStateNormal]; 40 | [self.addButton addTarget:self action:@selector(addButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; 41 | 42 | // 购物车按钮 43 | self.shoppingCartButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 120 - 50 - 20, self.addButton.frame.origin.y, 50, 50)]; 44 | [self.view addSubview:self.shoppingCartButton]; 45 | [self.shoppingCartButton setImage:[UIImage imageNamed:@"cart"] forState:UIControlStateNormal]; 46 | [self.shoppingCartButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 47 | 48 | // 商品数量label 49 | self.goodsNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.shoppingCartButton.center.x, self.shoppingCartButton.frame.origin.y, 30, 15)]; 50 | [self.view addSubview:self.goodsNumLabel]; 51 | self.goodsNumLabel.backgroundColor = [UIColor redColor]; 52 | self.goodsNumLabel.textColor = [UIColor whiteColor]; 53 | self.goodsNumLabel.textAlignment = NSTextAlignmentCenter; 54 | self.goodsNumLabel.font = [UIFont systemFontOfSize:10]; 55 | self.goodsNumLabel.layer.cornerRadius = 7; 56 | self.goodsNumLabel.clipsToBounds = YES; 57 | self.goodsNumLabel.text = @"99+"; 58 | } 59 | 60 | 61 | /** 加入购物车按钮点击 */ 62 | - (void)addButtonClicked:(UIButton *)sender { 63 | [ShoppingCartTool addToShoppingCartWithGoodsImage:[UIImage imageNamed:@"heheda"] startPoint:self.addButton.center endPoint:self.shoppingCartButton.center completion:^(BOOL finished) { 64 | NSLog(@"动画结束了"); 65 | 66 | //------- 颤抖吧 -------// 67 | CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; 68 | scaleAnimation.fromValue = [NSNumber numberWithFloat:1.0]; 69 | scaleAnimation.toValue = [NSNumber numberWithFloat:0.7]; 70 | scaleAnimation.duration = 0.1; 71 | scaleAnimation.repeatCount = 2; // 颤抖两次 72 | scaleAnimation.autoreverses = YES; 73 | scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 74 | [self.goodsNumLabel.layer addAnimation:scaleAnimation forKey:nil]; 75 | }]; 76 | } 77 | 78 | 79 | @end 80 | -------------------------------------------------------------------------------- /ShoppingCartAnimation/cart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CaiWanFeng/ShoppingCartAnimation/a70886743103f1b5f73697b813460893f2512cc5/ShoppingCartAnimation/cart.png -------------------------------------------------------------------------------- /ShoppingCartAnimation/heheda.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CaiWanFeng/ShoppingCartAnimation/a70886743103f1b5f73697b813460893f2512cc5/ShoppingCartAnimation/heheda.png -------------------------------------------------------------------------------- /ShoppingCartAnimation/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ShoppingCartAnimation 4 | // 5 | // Created by 蔡强 on 2017/7/17. 6 | // Copyright © 2017年 kuaijiankang. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | --------------------------------------------------------------------------------