Last active
January 28, 2016 15:40
-
-
Save stuffmc/05626b1cbb11fc3b233d to your computer and use it in GitHub Desktop.
Dynamic / Moving / Turning / Wheeling version of DonutChartInterfaceController.swift from YOChartImageKit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import WatchKit | |
import YOChartImageKit | |
class DonutChartInterfaceController: BaseInterfaceController { | |
let chart = YODonutChartImage() | |
var frame: CGRect? | |
var timer: NSTimer? | |
var startAngle = -M_PI_2 | |
var images: [UIImage]? | |
var index = 0 | |
override func willActivate() { | |
super.willActivate() | |
chart.donutWidth = 16.0 | |
chart.labelColor = UIColor.whiteColor() | |
chart.values = [30.0, 70.0] | |
chart.colors = [UIColor.clearColor(), UIColor.blueColor()] | |
frame = CGRectMake(0, 0, contentFrame.width, contentFrame.height / 1.5) | |
// This is obviously ridiculous! I'm now using UIImage.animatedImageWithImages(_, duration:) | |
// But you get the idea... | |
timer = NSTimer.scheduledTimerWithTimeInterval(0.1125, target: self, selector: "drawMe", userInfo: nil, repeats: true) | |
} | |
func prepareImages() { | |
print(startAngle) | |
chart.startAngle = CGFloat(startAngle) | |
let chunk = M_PI_4 / 4 | |
if startAngle > (M_PI + M_PI_2 - chunk) { | |
startAngle = -M_PI_2 | |
} else { | |
startAngle += chunk | |
} | |
let image = chart.drawImage(frame!, scale: WKInterfaceDevice.currentDevice().screenScale) | |
if images == nil { | |
images = [image] | |
} else { | |
images?.append(image) | |
} | |
} | |
func drawMe() { | |
if index < 32 { | |
prepareImages() | |
} else { | |
index = 0 | |
} | |
self.imageView.setImage(images![index]) | |
index += 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment