├── .github
└── FUNDING.yml
├── README.md
├── SparkButtonDemo.gif
├── SparkButtonDemo.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│ └── contents.xcworkspacedata
└── xcuserdata
│ └── saravananv.xcuserdatad
│ ├── xcdebugger
│ └── Breakpoints_v2.xcbkptlist
│ └── xcschemes
│ ├── SparkButtonDemo.xcscheme
│ └── xcschememanagement.plist
└── SparkButtonDemo
├── AppDelegate.swift
├── Assets.xcassets
├── AppIcon.appiconset
│ └── Contents.json
├── Contents.json
├── like.imageset
│ ├── Contents.json
│ ├── like-default.png
│ └── like-default@2x.png
├── liked.imageset
│ ├── Contents.json
│ ├── liked.png
│ └── liked@2x.png
└── spark.imageset
│ ├── Contents.json
│ └── spark.png
├── Base.lproj
├── LaunchScreen.storyboard
└── Main.storyboard
├── Info.plist
├── SparkButton
├── SparkButton.swift
└── SparkView.swift
└── ViewController.swift
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: saru2020 # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | custom: # Replace with a single custom sponsorship URL
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | SparkButtonDemo
2 | ===============
3 | Demonstrates the SparkButton Animations that reflects the FB's Paper App's Like button animation.
4 |
5 |
6 | There is also a writeup on the Imaginea blog.
7 |
8 | 
9 |
10 |
11 |
12 | Installation :
13 |
14 | (i) Import "SparkButton.swift" & "SparkView.swift" files into your project.
15 | (ii) Import QuartzCore framework into your project.
16 |
17 |
18 | Usage :
19 |
20 | On Your UIViewController's UI setup method, add these lines:
21 | ```swift
22 | let rect: CGRect = CGRectMake(100, 100, 40, 40)
23 | likeButton = SparkButton(frame: rect)
24 | self.view.addSubview(likeButton)
25 | ```
26 |
27 |
28 | Apps Using this Library :
29 |
30 | Fontli
31 |
32 |
33 |
34 |
35 | ## 👨🏻💻 Author
36 | [1.1]: http://i.imgur.com/tXSoThF.png
37 | [1]: http://www.twitter.com/saruhere
38 |
39 | * Saravanan [![alt text][1.1]][1]
40 |
41 |
42 |
--------------------------------------------------------------------------------
/SparkButtonDemo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saru2020/SparkButtonDemo/891c09426820108612cf1eb8f1b58817823bc88a/SparkButtonDemo.gif
--------------------------------------------------------------------------------
/SparkButtonDemo.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | EBF8775A1D02D861007B22C3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBF877591D02D861007B22C3 /* AppDelegate.swift */; };
11 | EBF8775C1D02D861007B22C3 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBF8775B1D02D861007B22C3 /* ViewController.swift */; };
12 | EBF8775F1D02D861007B22C3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EBF8775D1D02D861007B22C3 /* Main.storyboard */; };
13 | EBF877611D02D861007B22C3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EBF877601D02D861007B22C3 /* Assets.xcassets */; };
14 | EBF877641D02D861007B22C3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EBF877621D02D861007B22C3 /* LaunchScreen.storyboard */; };
15 | EBF8776F1D02D8E4007B22C3 /* SparkButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBF8776E1D02D8E4007B22C3 /* SparkButton.swift */; };
16 | EBF877711D02D8F0007B22C3 /* SparkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBF877701D02D8F0007B22C3 /* SparkView.swift */; };
17 | /* End PBXBuildFile section */
18 |
19 | /* Begin PBXFileReference section */
20 | EBF877561D02D860007B22C3 /* SparkButtonDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SparkButtonDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
21 | EBF877591D02D861007B22C3 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
22 | EBF8775B1D02D861007B22C3 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
23 | EBF8775E1D02D861007B22C3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
24 | EBF877601D02D861007B22C3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
25 | EBF877631D02D861007B22C3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
26 | EBF877651D02D861007B22C3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
27 | EBF8776E1D02D8E4007B22C3 /* SparkButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SparkButton.swift; sourceTree = ""; };
28 | EBF877701D02D8F0007B22C3 /* SparkView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SparkView.swift; sourceTree = ""; };
29 | /* End PBXFileReference section */
30 |
31 | /* Begin PBXFrameworksBuildPhase section */
32 | EBF877531D02D860007B22C3 /* Frameworks */ = {
33 | isa = PBXFrameworksBuildPhase;
34 | buildActionMask = 2147483647;
35 | files = (
36 | );
37 | runOnlyForDeploymentPostprocessing = 0;
38 | };
39 | /* End PBXFrameworksBuildPhase section */
40 |
41 | /* Begin PBXGroup section */
42 | EBF8774D1D02D860007B22C3 = {
43 | isa = PBXGroup;
44 | children = (
45 | EBF877581D02D861007B22C3 /* SparkButtonDemo */,
46 | EBF877571D02D860007B22C3 /* Products */,
47 | );
48 | sourceTree = "";
49 | };
50 | EBF877571D02D860007B22C3 /* Products */ = {
51 | isa = PBXGroup;
52 | children = (
53 | EBF877561D02D860007B22C3 /* SparkButtonDemo.app */,
54 | );
55 | name = Products;
56 | sourceTree = "";
57 | };
58 | EBF877581D02D861007B22C3 /* SparkButtonDemo */ = {
59 | isa = PBXGroup;
60 | children = (
61 | EBF8776D1D02D8E4007B22C3 /* SparkButton */,
62 | EBF877591D02D861007B22C3 /* AppDelegate.swift */,
63 | EBF8775B1D02D861007B22C3 /* ViewController.swift */,
64 | EBF8775D1D02D861007B22C3 /* Main.storyboard */,
65 | EBF877601D02D861007B22C3 /* Assets.xcassets */,
66 | EBF877621D02D861007B22C3 /* LaunchScreen.storyboard */,
67 | EBF877651D02D861007B22C3 /* Info.plist */,
68 | );
69 | path = SparkButtonDemo;
70 | sourceTree = "";
71 | };
72 | EBF8776D1D02D8E4007B22C3 /* SparkButton */ = {
73 | isa = PBXGroup;
74 | children = (
75 | EBF8776E1D02D8E4007B22C3 /* SparkButton.swift */,
76 | EBF877701D02D8F0007B22C3 /* SparkView.swift */,
77 | );
78 | path = SparkButton;
79 | sourceTree = "";
80 | };
81 | /* End PBXGroup section */
82 |
83 | /* Begin PBXNativeTarget section */
84 | EBF877551D02D860007B22C3 /* SparkButtonDemo */ = {
85 | isa = PBXNativeTarget;
86 | buildConfigurationList = EBF877681D02D861007B22C3 /* Build configuration list for PBXNativeTarget "SparkButtonDemo" */;
87 | buildPhases = (
88 | EBF877521D02D860007B22C3 /* Sources */,
89 | EBF877531D02D860007B22C3 /* Frameworks */,
90 | EBF877541D02D860007B22C3 /* Resources */,
91 | );
92 | buildRules = (
93 | );
94 | dependencies = (
95 | );
96 | name = SparkButtonDemo;
97 | productName = SparkButtonDemo;
98 | productReference = EBF877561D02D860007B22C3 /* SparkButtonDemo.app */;
99 | productType = "com.apple.product-type.application";
100 | };
101 | /* End PBXNativeTarget section */
102 |
103 | /* Begin PBXProject section */
104 | EBF8774E1D02D860007B22C3 /* Project object */ = {
105 | isa = PBXProject;
106 | attributes = {
107 | LastSwiftUpdateCheck = 0730;
108 | LastUpgradeCheck = 0730;
109 | ORGANIZATIONNAME = Saravanan;
110 | TargetAttributes = {
111 | EBF877551D02D860007B22C3 = {
112 | CreatedOnToolsVersion = 7.3.1;
113 | DevelopmentTeam = GY84S9P9XS;
114 | LastSwiftMigration = 0820;
115 | };
116 | };
117 | };
118 | buildConfigurationList = EBF877511D02D860007B22C3 /* Build configuration list for PBXProject "SparkButtonDemo" */;
119 | compatibilityVersion = "Xcode 3.2";
120 | developmentRegion = English;
121 | hasScannedForEncodings = 0;
122 | knownRegions = (
123 | en,
124 | Base,
125 | );
126 | mainGroup = EBF8774D1D02D860007B22C3;
127 | productRefGroup = EBF877571D02D860007B22C3 /* Products */;
128 | projectDirPath = "";
129 | projectRoot = "";
130 | targets = (
131 | EBF877551D02D860007B22C3 /* SparkButtonDemo */,
132 | );
133 | };
134 | /* End PBXProject section */
135 |
136 | /* Begin PBXResourcesBuildPhase section */
137 | EBF877541D02D860007B22C3 /* Resources */ = {
138 | isa = PBXResourcesBuildPhase;
139 | buildActionMask = 2147483647;
140 | files = (
141 | EBF877641D02D861007B22C3 /* LaunchScreen.storyboard in Resources */,
142 | EBF877611D02D861007B22C3 /* Assets.xcassets in Resources */,
143 | EBF8775F1D02D861007B22C3 /* Main.storyboard in Resources */,
144 | );
145 | runOnlyForDeploymentPostprocessing = 0;
146 | };
147 | /* End PBXResourcesBuildPhase section */
148 |
149 | /* Begin PBXSourcesBuildPhase section */
150 | EBF877521D02D860007B22C3 /* Sources */ = {
151 | isa = PBXSourcesBuildPhase;
152 | buildActionMask = 2147483647;
153 | files = (
154 | EBF8776F1D02D8E4007B22C3 /* SparkButton.swift in Sources */,
155 | EBF8775C1D02D861007B22C3 /* ViewController.swift in Sources */,
156 | EBF877711D02D8F0007B22C3 /* SparkView.swift in Sources */,
157 | EBF8775A1D02D861007B22C3 /* AppDelegate.swift in Sources */,
158 | );
159 | runOnlyForDeploymentPostprocessing = 0;
160 | };
161 | /* End PBXSourcesBuildPhase section */
162 |
163 | /* Begin PBXVariantGroup section */
164 | EBF8775D1D02D861007B22C3 /* Main.storyboard */ = {
165 | isa = PBXVariantGroup;
166 | children = (
167 | EBF8775E1D02D861007B22C3 /* Base */,
168 | );
169 | name = Main.storyboard;
170 | sourceTree = "";
171 | };
172 | EBF877621D02D861007B22C3 /* LaunchScreen.storyboard */ = {
173 | isa = PBXVariantGroup;
174 | children = (
175 | EBF877631D02D861007B22C3 /* Base */,
176 | );
177 | name = LaunchScreen.storyboard;
178 | sourceTree = "";
179 | };
180 | /* End PBXVariantGroup section */
181 |
182 | /* Begin XCBuildConfiguration section */
183 | EBF877661D02D861007B22C3 /* Debug */ = {
184 | isa = XCBuildConfiguration;
185 | buildSettings = {
186 | ALWAYS_SEARCH_USER_PATHS = NO;
187 | CLANG_ANALYZER_NONNULL = YES;
188 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
189 | CLANG_CXX_LIBRARY = "libc++";
190 | CLANG_ENABLE_MODULES = YES;
191 | CLANG_ENABLE_OBJC_ARC = YES;
192 | CLANG_WARN_BOOL_CONVERSION = YES;
193 | CLANG_WARN_CONSTANT_CONVERSION = YES;
194 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
195 | CLANG_WARN_EMPTY_BODY = YES;
196 | CLANG_WARN_ENUM_CONVERSION = YES;
197 | CLANG_WARN_INT_CONVERSION = YES;
198 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
199 | CLANG_WARN_UNREACHABLE_CODE = YES;
200 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
201 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
202 | COPY_PHASE_STRIP = NO;
203 | DEBUG_INFORMATION_FORMAT = dwarf;
204 | ENABLE_STRICT_OBJC_MSGSEND = YES;
205 | ENABLE_TESTABILITY = YES;
206 | GCC_C_LANGUAGE_STANDARD = gnu99;
207 | GCC_DYNAMIC_NO_PIC = NO;
208 | GCC_NO_COMMON_BLOCKS = YES;
209 | GCC_OPTIMIZATION_LEVEL = 0;
210 | GCC_PREPROCESSOR_DEFINITIONS = (
211 | "DEBUG=1",
212 | "$(inherited)",
213 | );
214 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
215 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
216 | GCC_WARN_UNDECLARED_SELECTOR = YES;
217 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
218 | GCC_WARN_UNUSED_FUNCTION = YES;
219 | GCC_WARN_UNUSED_VARIABLE = YES;
220 | IPHONEOS_DEPLOYMENT_TARGET = 9.3;
221 | MTL_ENABLE_DEBUG_INFO = YES;
222 | ONLY_ACTIVE_ARCH = YES;
223 | SDKROOT = iphoneos;
224 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
225 | TARGETED_DEVICE_FAMILY = "1,2";
226 | };
227 | name = Debug;
228 | };
229 | EBF877671D02D861007B22C3 /* Release */ = {
230 | isa = XCBuildConfiguration;
231 | buildSettings = {
232 | ALWAYS_SEARCH_USER_PATHS = NO;
233 | CLANG_ANALYZER_NONNULL = YES;
234 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
235 | CLANG_CXX_LIBRARY = "libc++";
236 | CLANG_ENABLE_MODULES = YES;
237 | CLANG_ENABLE_OBJC_ARC = YES;
238 | CLANG_WARN_BOOL_CONVERSION = YES;
239 | CLANG_WARN_CONSTANT_CONVERSION = YES;
240 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
241 | CLANG_WARN_EMPTY_BODY = YES;
242 | CLANG_WARN_ENUM_CONVERSION = YES;
243 | CLANG_WARN_INT_CONVERSION = YES;
244 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
245 | CLANG_WARN_UNREACHABLE_CODE = YES;
246 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
247 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
248 | COPY_PHASE_STRIP = NO;
249 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
250 | ENABLE_NS_ASSERTIONS = NO;
251 | ENABLE_STRICT_OBJC_MSGSEND = YES;
252 | GCC_C_LANGUAGE_STANDARD = gnu99;
253 | GCC_NO_COMMON_BLOCKS = YES;
254 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
255 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
256 | GCC_WARN_UNDECLARED_SELECTOR = YES;
257 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
258 | GCC_WARN_UNUSED_FUNCTION = YES;
259 | GCC_WARN_UNUSED_VARIABLE = YES;
260 | IPHONEOS_DEPLOYMENT_TARGET = 9.3;
261 | MTL_ENABLE_DEBUG_INFO = NO;
262 | SDKROOT = iphoneos;
263 | TARGETED_DEVICE_FAMILY = "1,2";
264 | VALIDATE_PRODUCT = YES;
265 | };
266 | name = Release;
267 | };
268 | EBF877691D02D861007B22C3 /* Debug */ = {
269 | isa = XCBuildConfiguration;
270 | buildSettings = {
271 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
272 | CODE_SIGN_IDENTITY = "iPhone Developer";
273 | INFOPLIST_FILE = SparkButtonDemo/Info.plist;
274 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
275 | PRODUCT_BUNDLE_IDENTIFIER = saravanan.SparkButtonDemo;
276 | PRODUCT_NAME = "$(TARGET_NAME)";
277 | SWIFT_VERSION = 3.0;
278 | };
279 | name = Debug;
280 | };
281 | EBF8776A1D02D861007B22C3 /* Release */ = {
282 | isa = XCBuildConfiguration;
283 | buildSettings = {
284 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
285 | CODE_SIGN_IDENTITY = "iPhone Developer";
286 | INFOPLIST_FILE = SparkButtonDemo/Info.plist;
287 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
288 | PRODUCT_BUNDLE_IDENTIFIER = saravanan.SparkButtonDemo;
289 | PRODUCT_NAME = "$(TARGET_NAME)";
290 | SWIFT_VERSION = 3.0;
291 | };
292 | name = Release;
293 | };
294 | /* End XCBuildConfiguration section */
295 |
296 | /* Begin XCConfigurationList section */
297 | EBF877511D02D860007B22C3 /* Build configuration list for PBXProject "SparkButtonDemo" */ = {
298 | isa = XCConfigurationList;
299 | buildConfigurations = (
300 | EBF877661D02D861007B22C3 /* Debug */,
301 | EBF877671D02D861007B22C3 /* Release */,
302 | );
303 | defaultConfigurationIsVisible = 0;
304 | defaultConfigurationName = Release;
305 | };
306 | EBF877681D02D861007B22C3 /* Build configuration list for PBXNativeTarget "SparkButtonDemo" */ = {
307 | isa = XCConfigurationList;
308 | buildConfigurations = (
309 | EBF877691D02D861007B22C3 /* Debug */,
310 | EBF8776A1D02D861007B22C3 /* Release */,
311 | );
312 | defaultConfigurationIsVisible = 0;
313 | defaultConfigurationName = Release;
314 | };
315 | /* End XCConfigurationList section */
316 | };
317 | rootObject = EBF8774E1D02D860007B22C3 /* Project object */;
318 | }
319 |
--------------------------------------------------------------------------------
/SparkButtonDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/SparkButtonDemo.xcodeproj/xcuserdata/saravananv.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
8 |
20 |
21 |
22 |
24 |
36 |
37 |
38 |
40 |
52 |
53 |
54 |
56 |
68 |
69 |
70 |
72 |
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/SparkButtonDemo.xcodeproj/xcuserdata/saravananv.xcuserdatad/xcschemes/SparkButtonDemo.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 |
--------------------------------------------------------------------------------
/SparkButtonDemo.xcodeproj/xcuserdata/saravananv.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | SparkButtonDemo.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | EBF877551D02D860007B22C3
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/SparkButtonDemo/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // SparkButtonDemo
4 | //
5 | // Created by Saravanan on 04/06/16.
6 | // Copyright © 2016 Saravanan. 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: [UIApplicationLaunchOptionsKey: Any]?) -> 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 |
--------------------------------------------------------------------------------
/SparkButtonDemo/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "20x20",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "20x20",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "29x29",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "29x29",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "40x40",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "40x40",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "size" : "60x60",
36 | "scale" : "2x"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "size" : "60x60",
41 | "scale" : "3x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "20x20",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "20x20",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "29x29",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "29x29",
61 | "scale" : "2x"
62 | },
63 | {
64 | "idiom" : "ipad",
65 | "size" : "40x40",
66 | "scale" : "1x"
67 | },
68 | {
69 | "idiom" : "ipad",
70 | "size" : "40x40",
71 | "scale" : "2x"
72 | },
73 | {
74 | "idiom" : "ipad",
75 | "size" : "76x76",
76 | "scale" : "1x"
77 | },
78 | {
79 | "idiom" : "ipad",
80 | "size" : "76x76",
81 | "scale" : "2x"
82 | },
83 | {
84 | "idiom" : "ipad",
85 | "size" : "83.5x83.5",
86 | "scale" : "2x"
87 | }
88 | ],
89 | "info" : {
90 | "version" : 1,
91 | "author" : "xcode"
92 | }
93 | }
--------------------------------------------------------------------------------
/SparkButtonDemo/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/SparkButtonDemo/Assets.xcassets/like.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "like-default.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "like-default@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/SparkButtonDemo/Assets.xcassets/like.imageset/like-default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saru2020/SparkButtonDemo/891c09426820108612cf1eb8f1b58817823bc88a/SparkButtonDemo/Assets.xcassets/like.imageset/like-default.png
--------------------------------------------------------------------------------
/SparkButtonDemo/Assets.xcassets/like.imageset/like-default@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saru2020/SparkButtonDemo/891c09426820108612cf1eb8f1b58817823bc88a/SparkButtonDemo/Assets.xcassets/like.imageset/like-default@2x.png
--------------------------------------------------------------------------------
/SparkButtonDemo/Assets.xcassets/liked.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "liked.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "liked@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "scale" : "3x"
16 | }
17 | ],
18 | "info" : {
19 | "version" : 1,
20 | "author" : "xcode"
21 | }
22 | }
--------------------------------------------------------------------------------
/SparkButtonDemo/Assets.xcassets/liked.imageset/liked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saru2020/SparkButtonDemo/891c09426820108612cf1eb8f1b58817823bc88a/SparkButtonDemo/Assets.xcassets/liked.imageset/liked.png
--------------------------------------------------------------------------------
/SparkButtonDemo/Assets.xcassets/liked.imageset/liked@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saru2020/SparkButtonDemo/891c09426820108612cf1eb8f1b58817823bc88a/SparkButtonDemo/Assets.xcassets/liked.imageset/liked@2x.png
--------------------------------------------------------------------------------
/SparkButtonDemo/Assets.xcassets/spark.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "spark.png",
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 | }
--------------------------------------------------------------------------------
/SparkButtonDemo/Assets.xcassets/spark.imageset/spark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saru2020/SparkButtonDemo/891c09426820108612cf1eb8f1b58817823bc88a/SparkButtonDemo/Assets.xcassets/spark.imageset/spark.png
--------------------------------------------------------------------------------
/SparkButtonDemo/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 |
--------------------------------------------------------------------------------
/SparkButtonDemo/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/SparkButtonDemo/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 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/SparkButtonDemo/SparkButton/SparkButton.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SparkButton.swift
3 | // SparkButtonDemo
4 | //
5 | // Created by Saravanan on 04/06/16.
6 | // Copyright © 2016 Saravanan. All rights reserved.
7 | //
8 |
9 | import Foundation
10 | import UIKit
11 |
12 | class SparkButton: UIButton{
13 |
14 | var sparkView:SparkView!
15 |
16 | // MARK: -Initializers
17 | override init (frame : CGRect) {
18 | super.init(frame : frame)
19 | setup()
20 | }
21 |
22 | convenience init () {
23 | self.init(frame:CGRect.zero)
24 | setup()
25 | }
26 |
27 | required init(coder aDecoder: NSCoder) {
28 | super.init(coder: aDecoder)!
29 | setup()
30 | }
31 |
32 | override func layoutSubviews() {
33 | super.layoutSubviews()
34 |
35 | self.sparkView.frame = self.bounds
36 | self.insertSubview(self.sparkView, at: 0)
37 | }
38 |
39 | // MARK: -Setup Methods
40 | func setup(){
41 | self.clipsToBounds = false;
42 |
43 | self.sparkView = SparkView()
44 | // self.sparkView.backgroundColor = UIColor.redColor()
45 | self.insertSubview(self.sparkView, at: 0)
46 | }
47 |
48 | func animate () {
49 | let delay = DispatchTime.now() + Double(Int64(0.1 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
50 | DispatchQueue.main.asyncAfter(deadline: delay) {
51 | self.sparkView.animate()
52 | };
53 | }
54 |
55 | // MARK: Bouncing Animations
56 | func likeBounce (_ duration: TimeInterval) {
57 | self.transform = CGAffineTransform.identity
58 | UIView.animateKeyframes(withDuration: duration, delay: 0, options: UIViewKeyframeAnimationOptions(), animations: {
59 |
60 | UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1/5, animations: {
61 | self.transform = CGAffineTransform(scaleX: 1.6, y: 1.6);
62 | })
63 |
64 | UIView.addKeyframe(withRelativeStartTime: 1/5, relativeDuration: 1/5, animations: {
65 | self.transform = CGAffineTransform(scaleX: 0.6, y: 0.6);
66 | })
67 |
68 | UIView.addKeyframe(withRelativeStartTime: 2/5, relativeDuration: 1/5, animations: {
69 | self.transform = CGAffineTransform(scaleX: 1.3, y: 1.3);
70 | })
71 |
72 | UIView.addKeyframe(withRelativeStartTime: 3/5, relativeDuration: 1/5, animations: {
73 | self.transform = CGAffineTransform(scaleX: 0.8, y: 0.8);
74 | })
75 |
76 | UIView.addKeyframe(withRelativeStartTime: 4/5, relativeDuration: 1/5, animations: {
77 | self.transform = CGAffineTransform(scaleX: 1.0, y: 1.0);
78 | })
79 |
80 | }, completion: {finished in
81 |
82 | })
83 |
84 | }
85 |
86 | func unLikeBounce (_ duration: TimeInterval) {
87 | self.transform = CGAffineTransform.identity
88 | UIView.animateKeyframes(withDuration: duration, delay: 0, options: UIViewKeyframeAnimationOptions(), animations: {
89 |
90 | UIView.addKeyframe(withRelativeStartTime: 1/5, relativeDuration: 1/5, animations: {
91 | self.transform = CGAffineTransform(scaleX: 0.6, y: 0.6);
92 | })
93 |
94 | UIView.addKeyframe(withRelativeStartTime: 3/5, relativeDuration: 1/5, animations: {
95 | self.transform = CGAffineTransform(scaleX: 0.8, y: 0.8);
96 | })
97 |
98 | UIView.addKeyframe(withRelativeStartTime: 4/5, relativeDuration: 1/5, animations: {
99 | self.transform = CGAffineTransform(scaleX: 1.0, y: 1.0);
100 | })
101 |
102 | }, completion: {finished in
103 |
104 | })
105 |
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/SparkButtonDemo/SparkButton/SparkView.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SparkView.swift
3 | // SparkButtonDemo
4 | //
5 | // Created by Saravanan on 04/06/16.
6 | // Copyright © 2016 Saravanan. All rights reserved.
7 | //
8 |
9 | import Foundation
10 | import UIKit
11 |
12 | class SparkView: UIView{
13 |
14 | var explosionInLayer:CAEmitterLayer!
15 | var explosionOutLayer:CAEmitterLayer!
16 |
17 | // MARK: -Initializers
18 | override init (frame : CGRect) {
19 | super.init(frame : frame)
20 | setup()
21 | }
22 |
23 | convenience init () {
24 | self.init(frame:CGRect.zero)
25 | setup()
26 | }
27 |
28 | required init(coder aDecoder: NSCoder) {
29 | super.init(coder: aDecoder)!
30 | setup()
31 | }
32 |
33 | override func layoutSubviews() {
34 | super.layoutSubviews()
35 | let center = CGPoint(x: self.bounds.midX, y: self.bounds.midY);
36 | self.explosionInLayer.emitterPosition = center;
37 | self.explosionOutLayer.emitterPosition = center;
38 | }
39 |
40 | // MARK: -Setup Methods
41 | func setup(){
42 | self.clipsToBounds = false
43 | self.isUserInteractionEnabled = false
44 | let image = UIImage(named: "spark")
45 | let particleScale:CGFloat = 0.06
46 | let particleScaleRange:CGFloat = 0.03
47 |
48 | let explosionOutCell = CAEmitterCell()
49 | explosionOutCell.name = "explosion";
50 | explosionOutCell.alphaRange = 0.40;
51 | explosionOutCell.alphaSpeed = -1.0;
52 | explosionOutCell.lifetime = 0.8;
53 | explosionOutCell.lifetimeRange = 0.4;
54 | explosionOutCell.birthRate = 0;
55 | explosionOutCell.velocity = 50.00;
56 | explosionOutCell.velocityRange = 8.00;
57 | explosionOutCell.contents = image?.cgImage
58 | explosionOutCell.scale = particleScale
59 | explosionOutCell.scaleRange = particleScaleRange
60 |
61 | self.explosionOutLayer = CAEmitterLayer()
62 | self.explosionOutLayer.name = "emitterLayer";
63 | self.explosionOutLayer.emitterShape = kCAEmitterLayerCircle;
64 | self.explosionOutLayer.emitterMode = kCAEmitterLayerOutline;
65 | self.explosionOutLayer.emitterSize = CGSize(width: 30, height: 0);
66 | self.explosionOutLayer.emitterCells = [explosionOutCell];
67 | self.explosionOutLayer.renderMode = kCAEmitterLayerOldestFirst;
68 | self.explosionOutLayer.masksToBounds = false;
69 | self.layer.addSublayer(self.explosionOutLayer)
70 |
71 | let explosionInCell = CAEmitterCell()
72 | explosionInCell.name = "charge";
73 | explosionInCell.alphaRange = 0.40;
74 | explosionInCell.alphaSpeed = -1.0;
75 | explosionInCell.lifetime = 0.4;
76 | explosionInCell.lifetimeRange = 0.2;
77 | explosionInCell.birthRate = 0;
78 | explosionInCell.velocity = -40.0;
79 | explosionInCell.velocityRange = 0.00;
80 | explosionInCell.contents = image?.cgImage
81 | explosionInCell.scale = particleScale
82 | explosionInCell.scaleRange = particleScaleRange
83 |
84 | self.explosionInLayer = CAEmitterLayer()
85 | self.explosionInLayer.name = "emitterLayer";
86 | self.explosionInLayer.emitterShape = kCAEmitterLayerCircle;
87 | self.explosionInLayer.emitterMode = kCAEmitterLayerOutline;
88 | self.explosionInLayer.emitterSize = CGSize(width: 30, height: 0);
89 | self.explosionInLayer.emitterCells = [explosionInCell];
90 | self.explosionInLayer.renderMode = kCAEmitterLayerOldestFirst;
91 | self.explosionInLayer.masksToBounds = false;
92 | self.layer.addSublayer(self.explosionInLayer)
93 |
94 | }
95 |
96 | func animate () {
97 | self.explosionInLayer.beginTime = CACurrentMediaTime();
98 | self.explosionInLayer.setValue(60, forKeyPath: "emitterCells.charge.birthRate")
99 | let delay = DispatchTime.now() + Double(Int64(0.2 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
100 | DispatchQueue.main.asyncAfter(deadline: delay) {
101 | self.explode()
102 | };
103 | }
104 |
105 | func explode () {
106 | self.explosionInLayer.setValue(0, forKeyPath: "emitterCells.charge.birthRate")
107 | self.explosionOutLayer.beginTime = CACurrentMediaTime();
108 | self.explosionOutLayer.setValue(500, forKeyPath: "emitterCells.explosion.birthRate")
109 | let delay = DispatchTime.now() + Double(Int64(0.1 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
110 | DispatchQueue.main.asyncAfter(deadline: delay) {
111 | self.stop()
112 | };
113 | }
114 |
115 | func stop () {
116 | self.explosionInLayer.setValue(0, forKeyPath: "emitterCells.charge.birthRate")
117 | self.explosionOutLayer.setValue(0, forKeyPath: "emitterCells.explosion.birthRate")
118 | }
119 |
120 |
121 |
122 |
123 |
124 |
125 | }
126 |
127 |
128 |
129 |
130 |
131 |
132 |
--------------------------------------------------------------------------------
/SparkButtonDemo/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // SparkButtonDemo
4 | //
5 | // Created by Saravanan on 04/06/16.
6 | // Copyright © 2016 Saravanan. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class ViewController: UIViewController {
12 |
13 | @IBOutlet weak var likeButton: SparkButton!
14 | var isLiked:Bool!
15 |
16 | override func viewDidLoad() {
17 | super.viewDidLoad()
18 |
19 | isLiked = false
20 | }
21 |
22 | @IBAction func likeButtonTapped(_ sender: AnyObject) {
23 | isLiked = !isLiked
24 | if isLiked == true {
25 | likeButton.setImage(UIImage(named: "liked"), for: UIControlState())
26 | likeButton.likeBounce(0.6)
27 | likeButton.animate()
28 | }
29 | else{
30 | likeButton.setImage(UIImage(named: "like"), for: UIControlState())
31 | likeButton.unLikeBounce(0.4)
32 | }
33 | }
34 |
35 | override func didReceiveMemoryWarning() {
36 | super.didReceiveMemoryWarning()
37 | // Dispose of any resources that can be recreated.
38 | }
39 |
40 |
41 | }
42 |
43 |
--------------------------------------------------------------------------------