-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathFirstViewController.swift
More file actions
36 lines (30 loc) · 1.47 KB
/
FirstViewController.swift
File metadata and controls
36 lines (30 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// FirstViewController.swift
// TransitionButton
//
// Created by Alaeddine M. on 11/1/15.
// Copyright (c) 2015 Alaeddine M. All rights reserved.
//
import UIKit
import TransitionButton // 1: First import the TransitionButton library
class FirstViewController: UIViewController {
@IBAction func buttonAction(_ button: TransitionButton) {
button.startAnimation() // 2: Then start the animation when the user tap the button
button.finishAnimationDuration = 0.6
let qualityOfServiceClass = DispatchQoS.QoSClass.background
let backgroundQueue = DispatchQueue.global(qos: qualityOfServiceClass)
backgroundQueue.async(execute: {
sleep(3) // 3: Do your networking task or background work here.
DispatchQueue.main.async(execute: { () -> Void in
// 4: Stop the animation, here you have three options for the `animationStyle` property:
// .expand: useful when the task has been compeletd successfully and you want to expand the button and transit to another view controller in the completion callback
// .shake: when you want to reflect to the user that the task did not complete successfly
// .normal
button.stopAnimation(animationStyle: .expand, completion: {
let secondVC = SecondViewController()
self.present(secondVC, animated: true, completion: nil)
})
})
})
}
}