Merge pull request #18 from veonik/moving-nyancat

NyanCat now moves across the touchbar.
This commit is contained in:
Vatsaev Aslan 2017-02-11 00:02:13 +01:00 committed by GitHub
commit 96c57be0ff

View file

@ -9,13 +9,13 @@
import Cocoa
class NyanCatCanvas: NSImageView {
var timer:Timer? = nil
var imageLoaded:Bool = false;
var xPosition: CGFloat = 0 {
var xPosition: CGFloat = -680 {
didSet {
self.frame = CGRect(x: xPosition, y: 0, width: 685, height: 30)
self.frame = CGRect(x: xPosition, y: 0, width: 680, height: 30)
}
}
@ -26,13 +26,16 @@ class NyanCatCanvas: NSImageView {
self.animates = true
if(self.timer == nil) {
timer = Timer.scheduledTimer(timeInterval: 0.01, target: self, selector: #selector(self.moveNyancat), userInfo: nil, repeats: true)
}
if(!self.imageLoaded){
self.downloadImage()
}
self.canDrawSubviewsIntoLayer = true
self.frame = CGRect(x: xPosition, y: 0, width: 685, height: 30)
self.frame = CGRect(x: xPosition, y: 0, width: 680, height: 30)
}
override func touchesBegan(with event: NSEvent) {
@ -44,6 +47,12 @@ class NyanCatCanvas: NSImageView {
}
public func moveNyancat() {
if (xPosition < 0) {
xPosition += 1
}
}
func downloadImage() {
let url = URL(string: "https://i.imgur.com/7pgdK28.gif")