喂
刚开始进入C4,到目前为止,我的经验很棒。
我现在正在用相机示例复制照片,由于某种原因,当我按照教程(http://www.c4ios.com/tutorials/takingSnapshots)中所述进行所有操作时,出现以下错误:
“'TakePhoto'的无可见@interface声明选择器'listenFor:from Object:'”(Take Photo是我正在使用的文件)
我想我必须在类定义中声明“imageWasCaptured”,但我不知道是什么?
有什么建议么?
更新:这是代码
https://github.com/susemiessner/Urban-Alphabets/tree/master/urbanAlphabets
或只是普通复制
TakePhoto.h
#import "C4CanvasController.h"
@interface TakePhoto : C4CanvasController
@end
TakePhoto.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
最佳答案
为了使您的概念发挥作用,您的方法中有几个漏洞将阻止您看到实际发生的任何事情。您的问题肯定是其中之一。
要回答您的问题: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;
@end
现在,
putImageOnCanvas
方法看起来像:-(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
关于ios - C4捕获相机图像示例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19405431/