To get your concept working there are a couple of holes in your approach that will prevent you from seeing anything actually happen. Your question is definitely one of them.
To answer your question:
listenFor:fromObject:
is unrecognized because it actually doesn't exist.
The intention of listenFor
methods is so that your app, or a specific object, can react to a notification or an action happening somewhere else in the application. So what you want to do is run a method when something happens.
Your method should be:
[self listenFor:@"imageWasCaptured" fromObject:cam andRunMethod:@"methodName"];
You want to listen for when the camera has finished capturing and then do something with that...
Other things I noticed...
If you want to use a C4Button
, then the following:
takePhotoButton=[UIButton buttonWithType: ROUNDEDRECT];
[takePhotoButton setTitle:@"TakePhoto" forState:UIControlStateNormal];
Should be:
takePhotoButton = [C4Button buttonWithType:ROUNDEDRECT];
[takePhotoButton setTitle:@"TakePhoto" forState:NORMAL];
Also, you're subclassing C4CanvasController
. To get your TakePhoto
object's view onto the main canvas you need to create it properly.
To do this in the main canvas I wrote the following in my workspace:
#import "C4Workspace.h"
#import "TakePhoto.h"
@implementation C4WorkSpace {
TakePhoto *tp;
}
-(void)setup {
tp = [TakePhoto new];
tp.canvas.frame = CGRectMake(30,
30,
self.canvas.width - 60,
self.canvas.height - 60);
tp.canvas.shadowOffset = CGSizeMake(10,10);
tp.canvas.shadowOpacity = 1.0f;
tp.canvas.userInteractionEnabled = YES;
[tp setup];
tp.mainCanvas = self.canvas;
[self.canvas addSubview:tp.canvas];
}
@end
And, finally, to get your camera's image onto the main canvas, I had do bridge a little. I created a property in TakePhoto
that lets me set the main canvas in your new controller. You'll notice in the code above the line that states tp.mainCanvas = self.canvas
...
The TakePhoto
header now looks like:
#import "C4CanvasController.h"
@interface TakePhoto : C4CanvasController
@property (readwrite, strong) C4Window *mainCanvas;
@end
And the putImageOnCanvas
method now looks like:
-(void)putCapturedImageOnCanvas{
C4Image *img = cam.capturedImage;
img.width=240;
// img.center=CGPointMake(self.canvas.width*2/3, self.canvas.center.y);
img.center = CGPointMake([C4Math randomInt:self.mainCanvas.width], [C4Math randomInt:self.mainCanvas.height]);
[self.mainCanvas addImage:img];
[self.mainCanvas bringSubviewToFront:self.canvas];
}
The last two lines put the image on the canvas and then make sure that the TakePhoto
canvas (i.e. the one with the camera) is brought to the foreground so the newly added image doesn't occlude it.
Because you're using a subclass of a C4CanvasController
your app structure looks like:
C4WorkSpace.canvas > TakePhoto.canvas > Camera