Skip to content

Commit

Permalink
Fix Core Animation implementation due to changes in Mojave layer-backing
Browse files Browse the repository at this point in the history
  • Loading branch information
alantai-zuhlke committed Nov 16, 2018
1 parent 7e51bb3 commit fbe2d63
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DevExcuses/Sources/DevExcusesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ class DevExcusesView: ScreenSaverView {

private func updateImageView(data: Data) {
let imageView = KenBurnsView(frame: self.frame)
self.addSubview(imageView)

imageView.animate(
image : NSImage(data: data),
Expand All @@ -329,6 +328,7 @@ class DevExcusesView: ScreenSaverView {
oldImageView.removeFromSuperview()
}

self.addSubview(imageView)
self.imageView = imageView
}

Expand Down
21 changes: 13 additions & 8 deletions DevExcuses/Sources/KenBurnsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ import Cocoa
final class KenBurnsView: NSImageView {
private let configs = Configs()

private var duration: TimeInterval = 15

func animate(image: NSImage?, alpha: CGFloat, duration: TimeInterval) {
self.image = image
self.image = image
self.alphaValue = alpha
self.duration = duration
}

guard let image = self.image else {
return
}
override var wantsUpdateLayer: Bool {
return true
}

let width = Double(image.size.width)
let height = Double(image.size.height)
override func makeBackingLayer() -> CALayer {
let width = Double(self.frame.size.width)
let height = Double(self.frame.size.height)
let maxScale = Double(self.configs.maxZoom) / 100
let fromScale = Double.random(min: 1, max: maxScale)
let toScale = Double.random(min: 1, max: maxScale)
Expand Down Expand Up @@ -40,8 +46,7 @@ final class KenBurnsView: NSImageView {
layer.add(xAnimation, forKey: xAnimation.keyPath)
layer.add(yAnimation, forKey: yAnimation.keyPath)

self.layer = layer
self.alphaValue = alpha
return layer
}

private static func randomTranslation(min: Double, max: Double, scale: Double) -> Double {
Expand Down

0 comments on commit fbe2d63

Please sign in to comment.