├── .gitignore ├── .swiftpm └── xcode │ └── package.xcworkspace │ └── contents.xcworkspacedata ├── Animatable.podspec ├── Example ├── Example.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── Example │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── SceneDelegate.swift │ └── ViewController.swift ├── LICENSE ├── Package.swift ├── README.md ├── Sources └── Animatable │ └── Animatable.swift └── Tests ├── AnimatableTests ├── AnimatableTests.swift └── XCTestManifests.swift └── LinuxMain.swift /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /Packages 4 | /*.xcodeproj 5 | xcuserdata/ 6 | -------------------------------------------------------------------------------- /.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Animatable.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "Animatable" 3 | s.version = "1.0.6" 4 | s.license = { :type => "MIT" } 5 | s.homepage = "https://github.com/GodL/Animatable" 6 | s.author = { "GodL" => "547188371@qq.com" } 7 | s.summary = "A simpler way to set coreAnimation with PropertyWrapper." 8 | 9 | s.source = { :git => "https://github.com/GodL/Animatable.git", :tag => "#{s.version}" } 10 | s.source_files = "Sources/Animatable/*.swift" 11 | 12 | s.swift_version = "5.0" 13 | 14 | s.ios.deployment_target = "9.0" 15 | end 16 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C9A388B82650E5CF00339B3D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9A388B72650E5CF00339B3D /* AppDelegate.swift */; }; 11 | C9A388BA2650E5CF00339B3D /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9A388B92650E5CF00339B3D /* SceneDelegate.swift */; }; 12 | C9A388BC2650E5CF00339B3D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9A388BB2650E5CF00339B3D /* ViewController.swift */; }; 13 | C9A388BF2650E5CF00339B3D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C9A388BD2650E5CF00339B3D /* Main.storyboard */; }; 14 | C9A388C12650E5D300339B3D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C9A388C02650E5D300339B3D /* Assets.xcassets */; }; 15 | C9A388C42650E5D300339B3D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C9A388C22650E5D300339B3D /* LaunchScreen.storyboard */; }; 16 | C9A388CC2650E5E900339B3D /* Animatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9A388CB2650E5E900339B3D /* Animatable.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | C9A388B42650E5CF00339B3D /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | C9A388B72650E5CF00339B3D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 22 | C9A388B92650E5CF00339B3D /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 23 | C9A388BB2650E5CF00339B3D /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 24 | C9A388BE2650E5CF00339B3D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 25 | C9A388C02650E5D300339B3D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | C9A388C32650E5D300339B3D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | C9A388C52650E5D300339B3D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | C9A388CB2650E5E900339B3D /* Animatable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Animatable.swift; path = ../../Sources/Animatable/Animatable.swift; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | C9A388B12650E5CF00339B3D /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | C9A388AB2650E5CF00339B3D = { 43 | isa = PBXGroup; 44 | children = ( 45 | C9A388B62650E5CF00339B3D /* Example */, 46 | C9A388B52650E5CF00339B3D /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | C9A388B52650E5CF00339B3D /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | C9A388B42650E5CF00339B3D /* Example.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | C9A388B62650E5CF00339B3D /* Example */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | C9A388B72650E5CF00339B3D /* AppDelegate.swift */, 62 | C9A388B92650E5CF00339B3D /* SceneDelegate.swift */, 63 | C9A388BB2650E5CF00339B3D /* ViewController.swift */, 64 | C9A388CB2650E5E900339B3D /* Animatable.swift */, 65 | C9A388BD2650E5CF00339B3D /* Main.storyboard */, 66 | C9A388C02650E5D300339B3D /* Assets.xcassets */, 67 | C9A388C22650E5D300339B3D /* LaunchScreen.storyboard */, 68 | C9A388C52650E5D300339B3D /* Info.plist */, 69 | ); 70 | path = Example; 71 | sourceTree = ""; 72 | }; 73 | /* End PBXGroup section */ 74 | 75 | /* Begin PBXNativeTarget section */ 76 | C9A388B32650E5CF00339B3D /* Example */ = { 77 | isa = PBXNativeTarget; 78 | buildConfigurationList = C9A388C82650E5D300339B3D /* Build configuration list for PBXNativeTarget "Example" */; 79 | buildPhases = ( 80 | C9A388B02650E5CF00339B3D /* Sources */, 81 | C9A388B12650E5CF00339B3D /* Frameworks */, 82 | C9A388B22650E5CF00339B3D /* Resources */, 83 | ); 84 | buildRules = ( 85 | ); 86 | dependencies = ( 87 | ); 88 | name = Example; 89 | productName = Example; 90 | productReference = C9A388B42650E5CF00339B3D /* Example.app */; 91 | productType = "com.apple.product-type.application"; 92 | }; 93 | /* End PBXNativeTarget section */ 94 | 95 | /* Begin PBXProject section */ 96 | C9A388AC2650E5CF00339B3D /* Project object */ = { 97 | isa = PBXProject; 98 | attributes = { 99 | LastSwiftUpdateCheck = 1250; 100 | LastUpgradeCheck = 1250; 101 | TargetAttributes = { 102 | C9A388B32650E5CF00339B3D = { 103 | CreatedOnToolsVersion = 12.5; 104 | }; 105 | }; 106 | }; 107 | buildConfigurationList = C9A388AF2650E5CF00339B3D /* Build configuration list for PBXProject "Example" */; 108 | compatibilityVersion = "Xcode 9.3"; 109 | developmentRegion = en; 110 | hasScannedForEncodings = 0; 111 | knownRegions = ( 112 | en, 113 | Base, 114 | ); 115 | mainGroup = C9A388AB2650E5CF00339B3D; 116 | productRefGroup = C9A388B52650E5CF00339B3D /* Products */; 117 | projectDirPath = ""; 118 | projectRoot = ""; 119 | targets = ( 120 | C9A388B32650E5CF00339B3D /* Example */, 121 | ); 122 | }; 123 | /* End PBXProject section */ 124 | 125 | /* Begin PBXResourcesBuildPhase section */ 126 | C9A388B22650E5CF00339B3D /* Resources */ = { 127 | isa = PBXResourcesBuildPhase; 128 | buildActionMask = 2147483647; 129 | files = ( 130 | C9A388C42650E5D300339B3D /* LaunchScreen.storyboard in Resources */, 131 | C9A388C12650E5D300339B3D /* Assets.xcassets in Resources */, 132 | C9A388BF2650E5CF00339B3D /* Main.storyboard in Resources */, 133 | ); 134 | runOnlyForDeploymentPostprocessing = 0; 135 | }; 136 | /* End PBXResourcesBuildPhase section */ 137 | 138 | /* Begin PBXSourcesBuildPhase section */ 139 | C9A388B02650E5CF00339B3D /* Sources */ = { 140 | isa = PBXSourcesBuildPhase; 141 | buildActionMask = 2147483647; 142 | files = ( 143 | C9A388BC2650E5CF00339B3D /* ViewController.swift in Sources */, 144 | C9A388CC2650E5E900339B3D /* Animatable.swift in Sources */, 145 | C9A388B82650E5CF00339B3D /* AppDelegate.swift in Sources */, 146 | C9A388BA2650E5CF00339B3D /* SceneDelegate.swift in Sources */, 147 | ); 148 | runOnlyForDeploymentPostprocessing = 0; 149 | }; 150 | /* End PBXSourcesBuildPhase section */ 151 | 152 | /* Begin PBXVariantGroup section */ 153 | C9A388BD2650E5CF00339B3D /* Main.storyboard */ = { 154 | isa = PBXVariantGroup; 155 | children = ( 156 | C9A388BE2650E5CF00339B3D /* Base */, 157 | ); 158 | name = Main.storyboard; 159 | sourceTree = ""; 160 | }; 161 | C9A388C22650E5D300339B3D /* LaunchScreen.storyboard */ = { 162 | isa = PBXVariantGroup; 163 | children = ( 164 | C9A388C32650E5D300339B3D /* Base */, 165 | ); 166 | name = LaunchScreen.storyboard; 167 | sourceTree = ""; 168 | }; 169 | /* End PBXVariantGroup section */ 170 | 171 | /* Begin XCBuildConfiguration section */ 172 | C9A388C62650E5D300339B3D /* Debug */ = { 173 | isa = XCBuildConfiguration; 174 | buildSettings = { 175 | ALWAYS_SEARCH_USER_PATHS = NO; 176 | CLANG_ANALYZER_NONNULL = YES; 177 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 178 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 179 | CLANG_CXX_LIBRARY = "libc++"; 180 | CLANG_ENABLE_MODULES = YES; 181 | CLANG_ENABLE_OBJC_ARC = YES; 182 | CLANG_ENABLE_OBJC_WEAK = YES; 183 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 184 | CLANG_WARN_BOOL_CONVERSION = YES; 185 | CLANG_WARN_COMMA = YES; 186 | CLANG_WARN_CONSTANT_CONVERSION = YES; 187 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 188 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 189 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 190 | CLANG_WARN_EMPTY_BODY = YES; 191 | CLANG_WARN_ENUM_CONVERSION = YES; 192 | CLANG_WARN_INFINITE_RECURSION = YES; 193 | CLANG_WARN_INT_CONVERSION = YES; 194 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 195 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 196 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 197 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 198 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 199 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 200 | CLANG_WARN_STRICT_PROTOTYPES = YES; 201 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 202 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 203 | CLANG_WARN_UNREACHABLE_CODE = YES; 204 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 205 | COPY_PHASE_STRIP = NO; 206 | DEBUG_INFORMATION_FORMAT = dwarf; 207 | ENABLE_STRICT_OBJC_MSGSEND = YES; 208 | ENABLE_TESTABILITY = YES; 209 | GCC_C_LANGUAGE_STANDARD = gnu11; 210 | GCC_DYNAMIC_NO_PIC = NO; 211 | GCC_NO_COMMON_BLOCKS = YES; 212 | GCC_OPTIMIZATION_LEVEL = 0; 213 | GCC_PREPROCESSOR_DEFINITIONS = ( 214 | "DEBUG=1", 215 | "$(inherited)", 216 | ); 217 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 218 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 219 | GCC_WARN_UNDECLARED_SELECTOR = YES; 220 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 221 | GCC_WARN_UNUSED_FUNCTION = YES; 222 | GCC_WARN_UNUSED_VARIABLE = YES; 223 | IPHONEOS_DEPLOYMENT_TARGET = 14.5; 224 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 225 | MTL_FAST_MATH = YES; 226 | ONLY_ACTIVE_ARCH = YES; 227 | SDKROOT = iphoneos; 228 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 229 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 230 | }; 231 | name = Debug; 232 | }; 233 | C9A388C72650E5D300339B3D /* Release */ = { 234 | isa = XCBuildConfiguration; 235 | buildSettings = { 236 | ALWAYS_SEARCH_USER_PATHS = NO; 237 | CLANG_ANALYZER_NONNULL = YES; 238 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 239 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 240 | CLANG_CXX_LIBRARY = "libc++"; 241 | CLANG_ENABLE_MODULES = YES; 242 | CLANG_ENABLE_OBJC_ARC = YES; 243 | CLANG_ENABLE_OBJC_WEAK = YES; 244 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 245 | CLANG_WARN_BOOL_CONVERSION = YES; 246 | CLANG_WARN_COMMA = YES; 247 | CLANG_WARN_CONSTANT_CONVERSION = YES; 248 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 249 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 250 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 251 | CLANG_WARN_EMPTY_BODY = YES; 252 | CLANG_WARN_ENUM_CONVERSION = YES; 253 | CLANG_WARN_INFINITE_RECURSION = YES; 254 | CLANG_WARN_INT_CONVERSION = YES; 255 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 256 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 257 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 258 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 259 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 260 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 261 | CLANG_WARN_STRICT_PROTOTYPES = YES; 262 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 263 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 264 | CLANG_WARN_UNREACHABLE_CODE = YES; 265 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 266 | COPY_PHASE_STRIP = NO; 267 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 268 | ENABLE_NS_ASSERTIONS = NO; 269 | ENABLE_STRICT_OBJC_MSGSEND = YES; 270 | GCC_C_LANGUAGE_STANDARD = gnu11; 271 | GCC_NO_COMMON_BLOCKS = YES; 272 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 273 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 274 | GCC_WARN_UNDECLARED_SELECTOR = YES; 275 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 276 | GCC_WARN_UNUSED_FUNCTION = YES; 277 | GCC_WARN_UNUSED_VARIABLE = YES; 278 | IPHONEOS_DEPLOYMENT_TARGET = 14.5; 279 | MTL_ENABLE_DEBUG_INFO = NO; 280 | MTL_FAST_MATH = YES; 281 | SDKROOT = iphoneos; 282 | SWIFT_COMPILATION_MODE = wholemodule; 283 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 284 | VALIDATE_PRODUCT = YES; 285 | }; 286 | name = Release; 287 | }; 288 | C9A388C92650E5D300339B3D /* Debug */ = { 289 | isa = XCBuildConfiguration; 290 | buildSettings = { 291 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 292 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 293 | CODE_SIGN_STYLE = Automatic; 294 | INFOPLIST_FILE = Example/Info.plist; 295 | LD_RUNPATH_SEARCH_PATHS = ( 296 | "$(inherited)", 297 | "@executable_path/Frameworks", 298 | ); 299 | PRODUCT_BUNDLE_IDENTIFIER = godl.github.com.Example; 300 | PRODUCT_NAME = "$(TARGET_NAME)"; 301 | SWIFT_VERSION = 5.0; 302 | TARGETED_DEVICE_FAMILY = "1,2"; 303 | }; 304 | name = Debug; 305 | }; 306 | C9A388CA2650E5D300339B3D /* Release */ = { 307 | isa = XCBuildConfiguration; 308 | buildSettings = { 309 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 310 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 311 | CODE_SIGN_STYLE = Automatic; 312 | INFOPLIST_FILE = Example/Info.plist; 313 | LD_RUNPATH_SEARCH_PATHS = ( 314 | "$(inherited)", 315 | "@executable_path/Frameworks", 316 | ); 317 | PRODUCT_BUNDLE_IDENTIFIER = godl.github.com.Example; 318 | PRODUCT_NAME = "$(TARGET_NAME)"; 319 | SWIFT_VERSION = 5.0; 320 | TARGETED_DEVICE_FAMILY = "1,2"; 321 | }; 322 | name = Release; 323 | }; 324 | /* End XCBuildConfiguration section */ 325 | 326 | /* Begin XCConfigurationList section */ 327 | C9A388AF2650E5CF00339B3D /* Build configuration list for PBXProject "Example" */ = { 328 | isa = XCConfigurationList; 329 | buildConfigurations = ( 330 | C9A388C62650E5D300339B3D /* Debug */, 331 | C9A388C72650E5D300339B3D /* Release */, 332 | ); 333 | defaultConfigurationIsVisible = 0; 334 | defaultConfigurationName = Release; 335 | }; 336 | C9A388C82650E5D300339B3D /* Build configuration list for PBXNativeTarget "Example" */ = { 337 | isa = XCConfigurationList; 338 | buildConfigurations = ( 339 | C9A388C92650E5D300339B3D /* Debug */, 340 | C9A388CA2650E5D300339B3D /* Release */, 341 | ); 342 | defaultConfigurationIsVisible = 0; 343 | defaultConfigurationName = Release; 344 | }; 345 | /* End XCConfigurationList section */ 346 | }; 347 | rootObject = C9A388AC2650E5CF00339B3D /* Project object */; 348 | } 349 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/Example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Example 4 | // 5 | // Created by 李浩 on 2021/5/16. 6 | // 7 | 8 | import UIKit 9 | 10 | @main 11 | class AppDelegate: UIResponder, UIApplicationDelegate { 12 | 13 | 14 | 15 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 16 | // Override point for customization after application launch. 17 | return true 18 | } 19 | 20 | // MARK: UISceneSession Lifecycle 21 | 22 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 23 | // Called when a new scene session is being created. 24 | // Use this method to select a configuration to create the new scene with. 25 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 26 | } 27 | 28 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 29 | // Called when the user discards a scene session. 30 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 31 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 32 | } 33 | 34 | 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Example/Example/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Example/Example/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Example/Example/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 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | $(PRODUCT_MODULE_NAME).SceneDelegate 36 | UISceneStoryboardFile 37 | Main 38 | 39 | 40 | 41 | 42 | UIApplicationSupportsIndirectInputEvents 43 | 44 | UILaunchStoryboardName 45 | LaunchScreen 46 | UIMainStoryboardFile 47 | Main 48 | UIRequiredDeviceCapabilities 49 | 50 | armv7 51 | 52 | UISupportedInterfaceOrientations 53 | 54 | UIInterfaceOrientationPortrait 55 | UIInterfaceOrientationLandscapeLeft 56 | UIInterfaceOrientationLandscapeRight 57 | 58 | UISupportedInterfaceOrientations~ipad 59 | 60 | UIInterfaceOrientationPortrait 61 | UIInterfaceOrientationPortraitUpsideDown 62 | UIInterfaceOrientationLandscapeLeft 63 | UIInterfaceOrientationLandscapeRight 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /Example/Example/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // Example 4 | // 5 | // Created by 李浩 on 2021/5/16. 6 | // 7 | 8 | import UIKit 9 | 10 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 11 | 12 | var window: UIWindow? 13 | 14 | 15 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 16 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 17 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 18 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 19 | guard let _ = (scene as? UIWindowScene) else { return } 20 | } 21 | 22 | func sceneDidDisconnect(_ scene: UIScene) { 23 | // Called as the scene is being released by the system. 24 | // This occurs shortly after the scene enters the background, or when its session is discarded. 25 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 26 | // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). 27 | } 28 | 29 | func sceneDidBecomeActive(_ scene: UIScene) { 30 | // Called when the scene has moved from an inactive state to an active state. 31 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 32 | } 33 | 34 | func sceneWillResignActive(_ scene: UIScene) { 35 | // Called when the scene will move from an active state to an inactive state. 36 | // This may occur due to temporary interruptions (ex. an incoming phone call). 37 | } 38 | 39 | func sceneWillEnterForeground(_ scene: UIScene) { 40 | // Called as the scene transitions from the background to the foreground. 41 | // Use this method to undo the changes made on entering the background. 42 | } 43 | 44 | func sceneDidEnterBackground(_ scene: UIScene) { 45 | // Called as the scene transitions from the foreground to the background. 46 | // Use this method to save data, release shared resources, and store enough scene-specific state information 47 | // to restore the scene back to its current state. 48 | } 49 | 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /Example/Example/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Example 4 | // 5 | // Created by 李浩 on 2021/5/16. 6 | // 7 | 8 | import UIKit 9 | 10 | var isRepeat: Bool = false 11 | 12 | class ViewController: UIViewController { 13 | 14 | @Animatable(animated: Animations.TranslationAnimation(), configure: { 15 | if isRepeat { 16 | $0.autoreverses = true 17 | $0.repeatCount = 100 18 | } 19 | }) 20 | var translationView: UILabel = UILabel() 21 | 22 | @Animatable(animated: Animations.ScaleAnimation(), configure: { 23 | if isRepeat { 24 | $0.autoreverses = true 25 | $0.repeatCount = 100 26 | } 27 | }) 28 | var scaleView: UILabel = UILabel() 29 | 30 | @Animatable(animated: AnimationGroup(Animations.TranslationAnimation(), Animations.ScaleAnimation()), configure: { 31 | if isRepeat { 32 | $0.autoreverses = true 33 | $0.repeatCount = 100 34 | } 35 | }) 36 | var combineView: UILabel = UILabel() 37 | 38 | override func viewDidLoad() { 39 | super.viewDidLoad() 40 | 41 | translationView.text = "平移" 42 | translationView.backgroundColor = .red 43 | translationView.textAlignment = .center 44 | translationView.frame = CGRect(x: 20, y: 100, width: 100, height: 30) 45 | self.view.addSubview(translationView) 46 | 47 | scaleView.text = "缩放" 48 | scaleView.backgroundColor = .orange 49 | scaleView.textAlignment = .center 50 | scaleView.frame = CGRect(x: self.view.center.x - 25, y: 180, width: 50, height: 50) 51 | self.view.addSubview(scaleView) 52 | 53 | combineView.text = "组合式动画" 54 | combineView.backgroundColor = .blue 55 | combineView.textAlignment = .center 56 | combineView.frame = CGRect(x: 20, y: 280, width: 100, height: 30) 57 | self.view.addSubview(combineView) 58 | 59 | let btn1 = UIButton(type: .custom) 60 | btn1.setTitle("执行一次", for: .normal) 61 | btn1.backgroundColor = .brown 62 | btn1.frame = CGRect(x: self.view.center.x - 130, y: 350, width: 100, height: 50) 63 | self.view.addSubview(btn1) 64 | 65 | let btn2 = UIButton(type: .custom) 66 | btn2.setTitle("重复执行", for: .normal) 67 | btn2.backgroundColor = .brown 68 | btn2.frame = CGRect(x: self.view.center.x + 30, y: 350, width: 100, height: 50) 69 | self.view.addSubview(btn2) 70 | 71 | btn1.addTarget(self, action: #selector(_do), for: .touchUpInside) 72 | btn2.addTarget(self, action: #selector(_doRepeat), for: .touchUpInside) 73 | 74 | let btn3 = UIButton(type: .custom) 75 | btn3.setTitle("移除", for: .normal) 76 | btn3.backgroundColor = .brown 77 | btn3.frame = CGRect(x: self.view.center.x - 30, y: 420, width: 60, height: 60) 78 | btn3.addTarget(self, action: #selector(remove), for: .touchUpInside) 79 | self.view.addSubview(btn3) 80 | // Do any additional setup after loading the view. 81 | } 82 | 83 | @objc func _do() { 84 | isRepeat = false 85 | `do`() 86 | } 87 | 88 | @objc func _doRepeat() { 89 | isRepeat = true 90 | `do`() 91 | } 92 | 93 | @objc func remove() { 94 | $translationView.stopAnimation() 95 | $scaleView.stopAnimation() 96 | $combineView.stopAnimation() 97 | } 98 | 99 | func `do`() { 100 | $translationView.startAnimation() 101 | $scaleView.startAnimation() 102 | $combineView.startAnimation() 103 | } 104 | } 105 | 106 | enum Animations { 107 | 108 | struct TranslationAnimation: AnimatedType { 109 | var animation: CAAnimation { 110 | let animation = CABasicAnimation(keyPath: "transform.translation.x") 111 | animation.duration = 2 112 | animation.toValue = 200 113 | return animation 114 | } 115 | } 116 | 117 | struct ScaleAnimation: AnimatedType { 118 | var animation: CAAnimation { 119 | let animation = CABasicAnimation(keyPath: "transform.scale") 120 | animation.duration = 2 121 | animation.toValue = 2 122 | return animation 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 GodL 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 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.3 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "Animatable", 8 | platforms: [ 9 | .iOS(.v9) 10 | ], 11 | products: [ 12 | .library( 13 | name: "Animatable", 14 | targets: ["Animatable"]), 15 | ], 16 | targets: [ 17 | .target( 18 | name: "Animatable", 19 | dependencies: []), 20 | .testTarget( 21 | name: "AnimatableTests", 22 | dependencies: ["Animatable"]), 23 | ] 24 | ) 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Animatable 2 | 3 | ✨ A simpler way to set coreAnimation with PropertyWrapper. 4 | 5 | ## At a Glance 6 | 7 | Initialize animations. 8 | 9 | ```swift 10 | enum Animations { 11 | struct TranslationAnimation: AnimatedType { 12 | var animation: CAAnimation { 13 | let animation = CABasicAnimation(keyPath: "transform.translation.x") 14 | animation.duration = 2 15 | animation.toValue = 200 16 | return animation 17 | } 18 | } 19 | 20 | struct ScaleAnimation: AnimatedType { 21 | var animation: CAAnimation { 22 | let animation = CABasicAnimation(keyPath: "transform.scale") 23 | animation.duration = 2 24 | animation.toValue = 2 25 | return animation 26 | } 27 | } 28 | } 29 | ``` 30 | Use animations with PropertyWrapper 31 | 32 | ``` swift 33 | @Animatable(animated: Animations.TranslationAnimation(), configure: { 34 | if isRepeat { 35 | $0.autoreverses = true 36 | $0.repeatCount = 100 37 | } 38 | }) 39 | var translationView: UILabel = UILabel() 40 | 41 | @Animatable(animated: Animations.ScaleAnimation(), configure: { 42 | if isRepeat { 43 | $0.autoreverses = true 44 | $0.repeatCount = 100 45 | } 46 | }) 47 | var scaleView: UILabel = UILabel() 48 | 49 | @Animatable(animated: AnimationGroup(Animations.TranslationAnimation(), Animations.ScaleAnimation()), configure: { 50 | if isRepeat { 51 | $0.autoreverses = true 52 | $0.repeatCount = 100 53 | } 54 | }) 55 | var combineView: UILabel = UILabel() 56 | 57 | $translationView.startAnimation() 58 | $scaleView.startAnimation() 59 | $combineView.startAnimation() 60 | ``` 61 | 62 | ## Tips 63 | 64 | You can use projectedValue $ to startAnimation and stopAnimation 65 | 66 | ## Installation 67 | 68 | - **Using [Swift Package Manager](https://swift.org/package-manager)**: 69 | 70 | ```swift 71 | import PackageDescription 72 | 73 | let package = Package( 74 | name: "MyAwesomeApp", 75 | dependencies: [ 76 | .Package(url: "https://github.com/GodL/Animatable.git", majorVersion: 1.0.6), 77 | ], 78 | targets: [ 79 | .target( 80 | name: "MyAwesomeApp", 81 | dependencies: ["Animatable"]) 82 | ] 83 | ) 84 | ``` 85 | 86 | - **Using [Cococpods]**: 87 | 88 | ``` ruby 89 | pod 'Animatable', '~> 1.0.6' 90 | ``` 91 | 92 | ## License 93 | 94 | **Animatable** is under MIT license. See the [LICENSE](LICENSE) file for more info. 95 | -------------------------------------------------------------------------------- /Sources/Animatable/Animatable.swift: -------------------------------------------------------------------------------- 1 | 2 | import UIKit 3 | 4 | public protocol AnimatedType { 5 | 6 | var animation: CAAnimation { get } 7 | 8 | var animationKey: String? { get } 9 | 10 | } 11 | 12 | extension AnimatedType { 13 | public var animationKey: String? { nil } 14 | } 15 | 16 | public struct AnimationGroup: AnimatedType { 17 | let animations: [AnimatedType] 18 | 19 | public var animation: CAAnimation { 20 | let group = CAAnimationGroup() 21 | group.animations = self.animations.map(\.animation) 22 | group.duration = group.animations?.first?.duration ?? 0 23 | return group 24 | } 25 | } 26 | 27 | extension AnimationGroup { 28 | public init(_ a1: A1, _ a2: A2) { 29 | animations = [a1,a2] 30 | } 31 | 32 | public init(_ a1: A1, _ a2: A2,_ a3: A3) { 33 | animations = [a1,a2,a3] 34 | } 35 | 36 | public init(_ a1: A1, _ a2: A2, _ a3: A3, _ a4: A4) { 37 | animations = [a1,a2,a3,a4] 38 | } 39 | } 40 | 41 | extension AnimationGroup { 42 | public init(_ animations: [A]) { 43 | self.animations = animations 44 | } 45 | 46 | public init(_ animations: A ...) { 47 | self.animations = animations 48 | } 49 | } 50 | 51 | @propertyWrapper 52 | public struct Animatable { 53 | 54 | let animation: A 55 | 56 | var configure: ((CAAnimation) -> Void)? 57 | 58 | public var projectedValue: Self { 59 | self 60 | } 61 | 62 | public var wrappedValue: Value 63 | 64 | public init(wrappedValue: Value, animated animation: A, configure: ((CAAnimation) -> Void)? = nil) { 65 | self.wrappedValue = wrappedValue 66 | self.animation = animation 67 | self.configure = configure 68 | } 69 | } 70 | 71 | extension Animatable where Value: UIView { 72 | public func startAnimation() { 73 | let key = animation.animationKey 74 | let animation = animation.animation 75 | configure?(animation) 76 | wrappedValue.layer.add(animation, forKey: key) 77 | } 78 | 79 | public func stopAnimation() { 80 | guard let key = animation.animationKey else { 81 | wrappedValue.layer.removeAllAnimations() 82 | return 83 | } 84 | wrappedValue.layer.removeAnimation(forKey: key) 85 | } 86 | } 87 | 88 | extension Animatable where Value: CALayer { 89 | public func startAnimation() { 90 | let key = animation.animationKey 91 | let animation = animation.animation 92 | configure?(animation) 93 | wrappedValue.add(animation, forKey: key) 94 | } 95 | 96 | public func stopAnimation() { 97 | guard let key = animation.animationKey else { 98 | wrappedValue.removeAllAnimations() 99 | return 100 | } 101 | wrappedValue.removeAnimation(forKey: key) 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /Tests/AnimatableTests/AnimatableTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | import UIKit 3 | @testable import Animatable 4 | 5 | 6 | final class AnimatableTests: XCTestCase { 7 | 8 | func testExample() { 9 | // This is an example of a functional test case. 10 | // Use XCTAssert and related functions to verify your tests produce the correct 11 | // results. 12 | } 13 | 14 | static var allTests = [ 15 | ("testExample", testExample), 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /Tests/AnimatableTests/XCTestManifests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | #if !canImport(ObjectiveC) 4 | public func allTests() -> [XCTestCaseEntry] { 5 | return [ 6 | testCase(AnimatableTests.allTests), 7 | ] 8 | } 9 | #endif 10 | -------------------------------------------------------------------------------- /Tests/LinuxMain.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | import AnimatableTests 4 | 5 | var tests = [XCTestCaseEntry]() 6 | tests += AnimatableTests.allTests() 7 | XCTMain(tests) 8 | --------------------------------------------------------------------------------