首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C4相机捕获-返回视图时出现的问题

C4相机捕获-返回视图时出现的问题
EN

Stack Overflow用户
提问于 2013-10-28 15:00:55
回答 1查看 56关注 0票数 1

我正在开发一个有几个子视图的应用程序。

目前我有4个子视图。这里是设置它们的C4Workspace代码

代码语言:javascript
复制
//TakePhoto
    takePhoto= [TakePhoto new];
    takePhoto.canvas.frame=CGRectMake(0, 0, self.canvas.width, self.canvas.height);
    takePhoto.canvas.userInteractionEnabled = YES;
    [takePhoto transferVariables:1 topBarFromTop:TopBarFromTopDefault topBarHeight:TopNavBarHeightDefault bottomBarHeight:BottomBarHeightDefault navBarColor:navBarColorDefault navigationColor:navigationColorDefault typeColor:typeColorDefault fatFont:fatFontDefault normalFont:normalFontDefault iconTakePhoto:iconTakePhoto iconClose:iconClose iconBack:iconBack];
    [takePhoto setup];
    [takePhoto cameraSetup];
    [self.canvas addSubview:takePhoto.canvas];

    //CropPhoto
    cropPhoto=[CropPhoto new];
    cropPhoto.canvas.frame=CGRectMake(0, 0, self.canvas.width, self.canvas.height);
    cropPhoto.canvas.userInteractionEnabled=YES;
    [cropPhoto transferVariables:1 topBarFroTop:TopBarFromTopDefault topBarHeight:TopNavBarHeightDefault bottomBarHeight:BottomBarHeightDefault navBarColor:navBarColorDefault navigationColor:navigationColorDefault typeColor:typeColorDefault overlayColor:overlayColorDefault fatFont:fatFontDefault normalFont:normalFontDefault iconClose:iconClose iconBack:iconBack iconOk:iconOk];
    [self.canvas addSubview:cropPhoto.canvas];
    cropPhoto.canvas.hidden= YES;

    //AssignPhoto
    assignLetter=[AssignLetter new];
    assignLetter.canvas.frame=CGRectMake(0, 0, self.canvas.width, self.canvas.height);
    assignLetter.canvas.userInteractionEnabled=YES;
    [assignLetter transferVariables:1 topBarFroTop:TopBarFromTopDefault topBarHeight:TopNavBarHeightDefault bottomBarHeight:BottomBarHeightDefault navBarColor:navBarColorDefault navigationColor:navigationColorDefault typeColor:typeColorDefault highlightColor:highlightColorDefault fatFont:fatFontDefault normalFont:normalFontDefault iconClose:iconClose iconBack:iconBack iconOk:iconOk iconSettings:iconSettings];

    [self.canvas addSubview:assignLetter.canvas ];
    assignLetter.canvas.hidden=YES;

    //AlphabetView
    alphabetView=[AlphabetView new];
    alphabetView.canvas.frame= CGRectMake(0, 0, self.canvas.width, self.canvas.height);
    alphabetView.canvas.userInteractionEnabled=YES;
    [alphabetView transferVaribles:1 topBarFromTop:TopBarFromTopDefault topBarHeight:TopNavBarHeightDefault bottomBarHeight:BottomBarHeightDefault navBarColor:navBarColorDefault navigationColor:navigationColorDefault typeColor:typeColorDefault darkenColor:darkenColorDefault fatFont:fatFontDefault normalFont:normalFontDefault iconClose:iconClose iconBack:iconBack iconMenu:iconMenu iconTakePhoto:iconTakePhoto iconAlphabetInfo:iconAlphabetInfo iconShareAlphabet:iconShareAlphabet iconWritePostcard:iconWritePostcard iconMyPostcards:iconMyPostcards iconMyAlphabets:iconMyAlphabets];
    [self.canvas addSubview:alphabetView.canvas];
    alphabetView.canvas.hidden=YES;

//the methods to listen for from all other canvasses
    [self listenFor:@"goToTakePhoto" andRunMethod:@"goToTakePhoto"];
    [self listenFor:@"goToCropPhoto" andRunMethod:@"goToCropPhoto"];
    [self listenFor:@"goToAssignPhoto" andRunMethod:@"goToAssignPhoto"];
    [self listenFor:@"goToAlphabetsView" andRunMethod:@"goToAlphabetsView"];

此主工作区还具有以下函数在视图之间切换

代码语言:javascript
复制
-(void)goToTakePhoto{
    [takePhoto resetCounter];
    [takePhoto setup];

    C4Log(@"TakePhoto");
    takePhoto.canvas.hidden=NO;
    cropPhoto.canvas.hidden=YES;
    assignLetter.canvas.hidden=YES;
    alphabetView.canvas.hidden=YES;
}
-(void)goToCropPhoto{
    C4Log(@"going to CropPhoto");
    [cropPhoto displayImage:takePhoto.img];
    [cropPhoto setup];
    takePhoto.canvas.hidden=YES;
    cropPhoto.canvas.hidden=NO;
    assignLetter.canvas.hidden=YES;
    alphabetView.canvas.hidden=YES;
}
-(void)goToAssignPhoto{
    C4Log(@"AssignPhoto");
    [assignLetter setup];
    [assignLetter drawCurrentAlphabet:currentAlphabet];
    [assignLetter drawCroppedPhoto:cropPhoto.croppedPhoto];
    takePhoto.canvas.hidden=YES;
    cropPhoto.canvas.hidden=YES;
    assignLetter.canvas.hidden=NO;
    alphabetView.canvas.hidden=YES;
}
-(void)goToAlphabetsView{
    C4Log(@"AlphabetsView");
    [alphabetView setup];
    [alphabetView drawCurrentAlphabet:assignLetter.currentAlphabet];
    takePhoto.canvas.hidden=YES;
    cropPhoto.canvas.hidden=YES;
    assignLetter.canvas.hidden=YES;
    alphabetView.canvas.hidden=NO;
}

第一个视图是拍摄与教程非常相似的照片(我为相机添加了一个重置计数器,因为我注意到拍摄照片的按钮总是在被点击时发送两次通知)。

代码语言:javascript
复制
-(void) setup{
photoButtonImage=iconTakePhoto;
    photoButtonImage.height=45;
    photoButtonImage.width=90;
    photoButtonImage.center=CGPointMake(self.canvas.width/2, self.canvas.height-bottomBarHeight/2);
    [self.canvas addImage:photoButtonImage];
    //gestures to take the photo
    [self listenFor:@"touchesBegan" fromObject:photoButtonImage andRunMethod:@"captureImage"];
    [self numberOfTouchesRequired:1 forGesture:@"capture"];
    [self listenFor:@"imageWasCaptured" fromObject:cam andRunMethod:@"goToCropPhoto"];
}

-(void)cameraSetup{
    cam = [C4Camera cameraWithFrame:CGRectMake(0,topBarFromTop+topBarHeight, self.canvas.width, self.canvas.height-(topBarHeight+bottomBarHeight+topBarFromTop))];
    cam.cameraPosition = CAMERABACK;
    [self.canvas addCamera:cam];
    [cam initCapture];
    counter=0;
}
-(void) captureImage{
    [cam captureImage];
    C4Log(@"capturing image");
}
-(void)resetCounter{
    counter=0;
}

只要我从一个C4Label导航回那个视图,它就能工作得很好,但是如果我是从一个图像导航回来的话,情况就不是这样了。即使我运行的是完全相同的函数,当我触摸到两者时。看起来是这样的:

代码语言:javascript
复制
//image as navigation element
takePhotoButton=iconTakePhoto;
    takePhotoButton.width=60;
    takePhotoButton.center=CGPointMake(takePhotoButton.width/2+5, bottomNavBar.center.y);
    [self.canvas addImage:takePhotoButton];
    [self listenFor:@"touchesBegan" fromObject:takePhotoButton andRunMethod:@"goToTakePhoto"];

//label as navigation element
takePhoto=[C4Label labelWithText:@"take Photo" font: normalFont];
    takePhoto.center=CGPointMake(self.canvas.width-(takePhoto.width/2+5), topNavBar.center.y);
    [self.canvas addLabel:takePhoto ];
    [self listenFor:@"touchesBegan" fromObject:takePhoto andRunMethod:@"goToTakePhoto"];

最后,这是发送te通知的视图中的函数。

代码语言:javascript
复制
-(void) goToTakePhoto{
    C4Log(@"goToTakePhoto");
    [self removeFromView]; //removes the currently displayed items from being displayed
    [self postNotification:@"goToTakePhoto"];
}

我现在可以用标签让它工作,但是用C4Image作为按钮会好得多.有什么想法吗?完整的代码可在Github上获得:http://github.com/susemiessner/Urban-Alphabets/tree/master/urbanAlphabetsII

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-30 13:20:01

我刚刚找到了这个问题的答案:当我回到镜头前,看到旧的

代码语言:javascript
复制
[self listenFor:@"imageWasCaptured" fromObject:cam andRunMethod:@"goToCropPhoto"];

仍然是活跃的,所以它认为我已经从相机捕捉到了一幅图像,这是不正确的。因此,解决方案是,当我离开视图时,我只需使用以下代码禁用它

代码语言:javascript
复制
[self stopListeningFor:@"imageWasCaptured" object:cam];

整个魔法都是这样的!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19638181

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档