Съемка камеры C4 - проблемы при возвращении к виду
Я работаю над приложением с несколькими подпредставлениями.
В настоящее время у меня есть 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
1 ответ
Я только что нашел ответ на этот вопрос: когда возвращаешься в камеру, видишь старый
[self listenFor:@"imageWasCaptured" fromObject:cam andRunMethod:@"goToCropPhoto"];
был все еще активен, поэтому он думает, что я уже захватил изображение с камеры, что не соответствует действительности. Таким образом, решение заключается в том, что когда я покидаю представление, мне просто нужно отключить это с помощью этого кода
[self stopListeningFor:@"imageWasCaptured" object:cam];
это делает всю магию!