嗨,
刚开始进入C4,到目前为止,我的经验是很棒的。我正在用相机复制一张照片--例如,由于某些原因,当我按照教程(http://www.c4ios.com/tutorials/takingSnapshots)的描述做所有事情时,我会犯以下错误:“TakePhoto没有可见的@接口,选择器'listenFor:from Object:‘(取照片是我正在工作的文件)我认为我必须在类定义中声明"imageWasCaptured”,但我不知道是什么?有什么建议吗?
更新:这是代码https://github.com/susemiessner/Urban-Alphabets/tree/master/urbanAlphabets,或者只是普通复制的TakePhoto.h
#import "C4CanvasController.h"
@interface TakePhoto : C4CanvasController
@endTakePhoto.m
#import "TakePhoto.h"
#define NavBarHeight 42
#define TopBarFromTop 20
@interface TakePhoto ()
@end
@implementation TakePhoto {
//common variables
UIColor *navBarColor;
UIColor *buttonColor;
UIColor *typeColor;
//top toolbar
C4Shape *topNavBar;
C4Font *fatFont;
C4Label *takePhoto;
//camera
C4Camera *cam;
//bottom Toolbar
C4Shape *bottomNavBar;
C4Button *takePhotoButton;
}
-(void) setup{
navBarColor=[UIColor colorWithRed:0.96875 green:0.96875 blue:0.96875 alpha:1];
buttonColor= [UIColor colorWithRed:0.8984275 green:0.8984275 blue:0.8984275 alpha:1];
typeColor=[UIColor colorWithRed:0.19921875 green:0.19921875 blue:0.19921875 alpha:1];
[self topBarSetup];
[self bottomBarSetup];
[self cameraSetup];
}
-(void)topBarSetup{
topNavBar=[C4Shape rect:CGRectMake(0, TopBarFromTop, self.canvas.width, NavBarHeight)];
topNavBar.fillColor=navBarColor;
topNavBar.lineWidth=0;
[self.canvas addShape:topNavBar];
fatFont=[C4Font fontWithName:@"HelveticaNeue-Bold" size:17];
takePhoto = [C4Label labelWithText:@"Take Photo" font:fatFont];
takePhoto.center=topNavBar.center;
[self.canvas addLabel:takePhoto];}
-(void)cameraSetup{
cam = [C4Camera cameraWithFrame:CGRectMake(0,TopBarFromTop+NavBarHeight, self.canvas.width, self.canvas.height-(2*NavBarHeight+TopBarFromTop))];
[self.canvas addCamera:cam];
[cam initCapture];
//tapping to take image
[self addGesture:TAP name:@"capture" action:@"capturedImage"];
[self numberOfTouchesRequired:1 forGesture:@"capture"];
//the following line is where I get the error
[self listenFor:@"imageWasCaptured" fromObject:@"putCapturedImageOnCanvas"];
}
-(void) bottomBarSetup{
bottomNavBar=[C4Shape rect:CGRectMake(0, self.canvas.height-(NavBarHeight), self.canvas.width, NavBarHeight)];
bottomNavBar.fillColor= navBarColor;
bottomNavBar.lineWidth=0;
[self.canvas addShape:bottomNavBar];
takePhotoButton=[UIButton buttonWithType: ROUNDEDRECT];
[takePhotoButton setTitle:@"TakePhoto" forState:UIControlStateNormal];
takePhotoButton.frame=CGRectMake(self.canvas.width/2-50, self.canvas.height-(NavBarHeight), 100, NavBarHeight);
takePhotoButton.backgroundColor=buttonColor;
takePhotoButton.tintColor=typeColor;
[self.canvas addSubview:takePhotoButton];
}
-(void) takingPhoto{
[cam captureImage];
}
-(void) captureImage{
[cam captureImage];
}
-(void)putCapturedImageOnCanvas{
C4Image *img = cam.capturedImage;
img.width=240;
img.center=CGPointMake(self.canvas.width*2/3, self.canvas.center.y);
}
@end发布于 2013-10-17 17:38:56
为了让你的概念发挥作用,在你的方法中有几个漏洞会阻止你看到任何实际发生的事情。你的问题绝对是其中之一。
回答你的问题:
listenFor:fromObject:是不被识别的,因为它实际上并不存在。
listenFor方法的目的是使应用程序或特定对象能够对应用程序中其他地方发生的通知或操作做出反应。,所以,,您想要做的是在发生事情时运行一个方法。
你的方法应该是:
[self listenFor:@"imageWasCaptured" fromObject:cam andRunMethod:@"methodName"];你想听摄像机拍完后用它做点什么.
其他我注意到的事情..。
如果要使用C4Button,请执行以下操作:
takePhotoButton=[UIButton buttonWithType: ROUNDEDRECT];
[takePhotoButton setTitle:@"TakePhoto" forState:UIControlStateNormal];应:
takePhotoButton = [C4Button buttonWithType:ROUNDEDRECT];
[takePhotoButton setTitle:@"TakePhoto" forState:NORMAL];此外,您还在子类C4CanvasController。要将TakePhoto对象的视图放到主画布上,需要正确地创建它。
要在主画布中这样做,我在工作区中编写了以下内容:
#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最后,为了把相机的图像放到主画布上,我做了一些桥牌。我在TakePhoto中创建了一个属性,允许我在新控制器中设置主画布。你会注意到在代码上面的一行,上面写着tp.mainCanvas = self.canvas.
TakePhoto头现在看起来如下:
#import "C4CanvasController.h"
@interface TakePhoto : C4CanvasController
@property (readwrite, strong) C4Window *mainCanvas;
@endputImageOnCanvas方法现在看起来如下所示:
-(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];
}最后两行将图像放在画布上,然后确保将TakePhoto画布(即带有摄像机的画布)带到前台,这样新添加的图像就不会将其遮挡。
因为您使用的是C4CanvasController的子类,所以应用程序结构如下所示:
C4WorkSpace.canvas > TakePhoto.canvas > Camera
https://stackoverflow.com/questions/19405431
复制相似问题