【问题标题】:C4 camera capture - problems when coming back to the viewC4 相机捕捉 - 回到视图时的问题
【发布时间】:2013-10-28 15:00:55
【问题描述】:

我正在开发一个包含多个子视图的应用程序。

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

//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"];

这个主工作区还有以下功能可以在视图之间切换

-(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;
}

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

-(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 导航回该视图,它就可以正常工作,但如果我从图像导航回来,则不会。即使我在触摸两者时运行完全相同的功能。 它看起来像这样:

//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"];

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

-(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

【问题讨论】:

  • 很难编译您的项目,github repo 缺少图像,可能还有一些其他文件。你能做到:fromObject:theImageYouWantToUse 而不是takePhoto 标签?
  • 这就是我在这里所做的:'[self listenFor:@"touchesBegan" fromObject:takePhotoButton andRunMethod:@"goToTakePhoto"];'而且它还可以立即触发在下一个屏幕中拍照的按钮...

标签: ios objective-c image-capture c4


【解决方案1】:

我刚刚找到了这个问题的答案: 当回到相机查看旧的

[self listenFor:@"imageWasCaptured" fromObject:cam andRunMethod:@"goToCropPhoto"];

仍然处于活动状态,因此它认为我已经从相机捕获了图像,这是不正确的。所以解决方案是当我离开视图时,我只需要使用此代码禁用它

[self stopListeningFor:@"imageWasCaptured" object:cam];

这就是全部的魔法!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-09
    • 2017-06-19
    • 2012-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多