Skip to content

Commit

Permalink
Reformat demo files
Browse files Browse the repository at this point in the history
  • Loading branch information
kaishin committed Jun 24, 2024
1 parent 2b61665 commit 5745b3b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 26 deletions.
5 changes: 4 additions & 1 deletion Demo/Demo-iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import UIKit
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
return true
}
}
5 changes: 3 additions & 2 deletions Demo/Demo-iOS/EmptyViewController.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import UIKit
import Gifu
import UIKit

class EmptyViewController: UIViewController {
let imageView = GIFImageView(image: #imageLiteral(resourceName: "mugen.gif"))

lazy var customImageView: CustomAnimatedView = {
return CustomAnimatedView(frame: CGRect(x: 0, y: self.view.frame.height - 200, width: 360, height: 200))
return CustomAnimatedView(
frame: CGRect(x: 0, y: self.view.frame.height - 200, width: 360, height: 200))
}()

override func viewDidLoad() {
Expand Down
9 changes: 6 additions & 3 deletions Demo/Demo-iOS/UIImageViewExtension.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import UIKit
import Gifu
import UIKit

extension UIImageView: GIFAnimatable {
private struct AssociatedKeys {
Expand All @@ -12,7 +12,8 @@ extension UIImageView: GIFAnimatable {

public var animator: Animator? {
get {
guard let animator = objc_getAssociatedObject(self, &AssociatedKeys.AnimatorKey) as? Animator else {
guard let animator = objc_getAssociatedObject(self, &AssociatedKeys.AnimatorKey) as? Animator
else {
let animator = Animator(withDelegate: self)
self.animator = animator
return animator
Expand All @@ -22,7 +23,9 @@ extension UIImageView: GIFAnimatable {
}

set {
objc_setAssociatedObject(self, &AssociatedKeys.AnimatorKey, newValue as Animator?, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
objc_setAssociatedObject(
self, &AssociatedKeys.AnimatorKey, newValue as Animator?, .OBJC_ASSOCIATION_RETAIN_NONATOMIC
)
}
}
}
30 changes: 19 additions & 11 deletions Demo/Demo-iOS/ViewController.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import UIKit
import Gifu
import UIKit

class ViewController: UIViewController {
@IBOutlet weak var imageView: GIFImageView!
@IBOutlet weak var imageDataLabel: UILabel!
@IBOutlet weak var memoryUsageLabel: UILabel!
@IBAction func unwindToRootViewController(segue: UIStoryboardSegue) { }
@IBAction func unwindToRootViewController(segue: UIStoryboardSegue) {}

var currentGIFName: String = "earth" {
didSet {
Expand Down Expand Up @@ -43,18 +43,24 @@ class ViewController: UIViewController {
func animate() {
imageView.setFrameBufferSize(1)

imageView.animate(withGIFNamed: currentGIFName, preparationBlock: {
DispatchQueue.main.async {
self.imageDataLabel.text = self.currentGIFName.capitalized + " (\(self.imageView.frameCount) frames / \(String(format: "%.2f", self.imageView.gifLoopDuration))s)"
}
}, loopBlock: {
imageView.animate(
withGIFNamed: currentGIFName,
preparationBlock: {
DispatchQueue.main.async {
self.imageDataLabel.text =
self.currentGIFName.capitalized
+ " (\(self.imageView.frameCount) frames / \(String(format: "%.2f", self.imageView.gifLoopDuration))s)"
}
},
loopBlock: {
print("Loop finished")
})
})

if #available(iOS 15.0, *) {
Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
DispatchQueue.main.async {
self.memoryUsageLabel.text = "Memory usage: \(Memory.memoryFootprint()!.formatted(.byteCount(style: .memory)))"
self.memoryUsageLabel.text =
"Memory usage: \(Memory.memoryFootprint()!.formatted(.byteCount(style: .memory)))"
}
}
}
Expand All @@ -64,8 +70,10 @@ class ViewController: UIViewController {
class Memory: NSObject {
// https://forums.developer.apple.com/thread/105088#357415
class func memoryFootprint() -> Int? {
let TASK_VM_INFO_COUNT = mach_msg_type_number_t(MemoryLayout<task_vm_info_data_t>.size / MemoryLayout<integer_t>.size)
let TASK_VM_INFO_REV1_COUNT = mach_msg_type_number_t(MemoryLayout.offset(of: \task_vm_info_data_t.min_address)! / MemoryLayout<integer_t>.size)
let TASK_VM_INFO_COUNT = mach_msg_type_number_t(
MemoryLayout<task_vm_info_data_t>.size / MemoryLayout<integer_t>.size)
let TASK_VM_INFO_REV1_COUNT = mach_msg_type_number_t(
MemoryLayout.offset(of: \task_vm_info_data_t.min_address)! / MemoryLayout<integer_t>.size)

var info = task_vm_info_data_t()
var count = TASK_VM_INFO_COUNT
Expand Down
8 changes: 4 additions & 4 deletions Demo/Demo-tvOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// Override point for customization after application launch.
return true
}
Expand All @@ -28,6 +30,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// 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.
}


}

5 changes: 1 addition & 4 deletions Demo/Demo-tvOS/ViewController.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import UIKit
import Gifu

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var imageView: GIFImageView!


override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
Expand All @@ -20,4 +18,3 @@ class ViewController: UIViewController {
imageView.animate(withGIFNamed: "mugen")
}
}

1 change: 0 additions & 1 deletion Sources/Gifu/Classes/GIFImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import UIKit

/// Example class that conforms to `GIFAnimatable`. Uses default values for the animator frame buffer count and resize behavior. You can either use it directly in your code or use it as a blueprint for your own subclass.
public class GIFImageView: UIImageView, GIFAnimatable {

/// A lazy animator.
public lazy var animator: Animator? = {
return Animator(withDelegate: self)
Expand Down

0 comments on commit 5745b3b

Please sign in to comment.