Skip to content

Instantly share code, notes, and snippets.

@C4Tutorials
Last active December 16, 2015 07:38
Show Gist options
  • Save C4Tutorials/5399635 to your computer and use it in GitHub Desktop.
Save C4Tutorials/5399635 to your computer and use it in GitHub Desktop.
Taking Snapshots Tutorial
//
// C4WorkSpace.m
// Taking Snapshots Tutorial
//
// Created by Travis Kirton.
//
#import "C4WorkSpace.h"
@implementation C4WorkSpace {
C4Camera *cam;
}
-(void)setup {
cam = [C4Camera cameraWithFrame:CGRectMake(0, 0, 240, 320)];
[self.canvas addCamera:cam];
[cam initCapture];
[self styleCamera];
[self addGesture:TAP name:@"capture" action:@"captureImage"];
[self numberOfTouchesRequired:1 forGesture:@"capture"];
[self listenFor:@"imageWasCaptured" fromObject:cam andRunMethod:@"putCapturedImageOnCanvas"];
[self addGesture:TAP name:@"frontBack" action:@"switchFrontBack"];
[self numberOfTouchesRequired:2 forGesture:@"frontBack"];
}
-(void)styleCamera {
cam.center = CGPointMake(self.canvas.width / 3, self.canvas.center.y);
cam.borderColor = [UIColor whiteColor];
cam.borderWidth = 1.0f;
cam.shadowOpacity = 0.8f;
cam.shadowOffset = CGSizeMake(5,5);
cam.zPosition = 5000;
}
-(void)captureImage {
[cam captureImage];
}
-(void)switchFrontBack {
cam.animationDuration = 1.0f;
cam.perspectiveDistance = 500.0f;
cam.rotationY += TWO_PI;
if(cam.cameraPosition == CAMERAFRONT || cam.cameraPosition == CAMERAUNSPECIFIED) {
cam.cameraPosition = CAMERABACK;
} else {
cam.cameraPosition = CAMERAFRONT;
}
}
-(void)putCapturedImageOnCanvas {
C4Image *img = cam.capturedImage;
img.width = 240.0f;
img.center = CGPointMake(self.canvas.width * 2 / 3, self.canvas.center.y);
[self addInteraction:img];
[self.canvas addImage:img];
}
-(void)addInteraction:(C4Image *)img {
[img addGesture:PAN name:@"move" action:@"move:"];
[img addGesture:TAP name:@"remove" action:@"removeFromSuperview"];
[img numberOfTapsRequired:2 forGesture:@"remove"];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment