Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple demo of ScreenRecorder... Creates animated points when the user quickly flicks the screen.
// import C4
import UIKit
class WorkSpace: CanvasController {
var screenRecorder: ScreenRecorder?
override func setup() {
self.screenRecorder = ScreenRecorder()
self.screenRecorder?.recordingEndedAction = {
self.screenRecorder?.showPreviewInController(self)
}
addPan()
addStartRecording()
}
func addStartRecording() {
canvas.addLongPressGestureRecognizer { (locations, center, state) in
if state == .Began && !self.screenRecorder!.recording {
ShapeLayer.disableActions = true
let r = Rectangle(frame: self.canvas.bounds)
self.canvas.add(r)
let a = ViewAnimation(duration: 0.25) {
r.opacity = 0.0
}
a.addCompletionObserver {
r.removeFromSuperview()
self.screenRecorder?.start(5.0)
}
a.animate()
}
}
}
func addPan() {
canvas.addPanGestureRecognizer { (locations, center, translation, velocity, state) in
if state == .Began {
for location in locations {
ShapeLayer.disableActions = true
let c = Circle(center: location, radius: 1)
self.canvas.add(c)
ShapeLayer.disableActions = false
let a = ViewAnimation(duration: 0.5) {
let newC = Circle(center: location, radius: 50.0)
c.path = newC.path
c.adjustToFitPath()
c.center = location
c.opacity = 0.0
}
a.addCompletionObserver() {
c.removeFromSuperview()
}
a.animate()
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment