mirror of
https://github.com/avatsaev/touchbar_nyancat
synced 2024-11-24 20:23:06 +00:00
Merge pull request #18 from veonik/moving-nyancat
NyanCat now moves across the touchbar.
This commit is contained in:
commit
96c57be0ff
1 changed files with 15 additions and 6 deletions
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue