0
我有一個CCLayer,我需要添加一個攝像頭,最重要的是,我需要一個自定義按鈕來關閉相機覆蓋到相機上。我最終需要在其上顯示CCSprites,但首先需要能夠關閉相機。從Cocos2D刪除UIImagePickerController
但是當我按一下按鈕,我得到SIGABRT或壞的EXE錯誤,這取決於我是否使用[[[CCDirector sharedDirector] openGLView] sendSubviewToBack:uip.view];
或[uip.view removeFromSuperview];
-(void) displayCamera
{
uip = [[[UIImagePickerController alloc] init] autorelease];
uip.sourceType = UIImagePickerControllerSourceTypeCamera;
uip.showsCameraControls = NO;
uip.toolbarHidden = YES;
uip.navigationBarHidden = YES;
uip.wantsFullScreenLayout = YES;
[[[CCDirector sharedDirector] openGLView] addSubview:uip.view];
UIButton *arrowButton = [UIButton buttonWithType:UIButtonTypeCustom];
[arrowButton addTarget:self
action:@selector(arrowButtonClicked:)
forControlEvents:UIControlEventTouchUpInside];
UIImage *imgNormal = [UIImage imageNamed:@"btn_next_norm.png"];
[arrowButton setImage:imgNormal forState:UIControlStateNormal];
UIImage *imgPressed = [UIImage imageNamed:@"btn_next_pressed.png"];
[arrowButton setImage:imgPressed forState:UIControlStateHighlighted];
arrowButton.frame = CGRectMake(screenSize.width - 48.0, screenSize.height - 37.0, 48.0, 37.0);
[[[CCDirector sharedDirector] openGLView] addSubview:arrowButton];
}
-(void)arrowButtonClicked:(id)sender
{
// close/hide camera
[[[CCDirector sharedDirector] openGLView] sendSubviewToBack:uip.view];
// or maybe [uip.view removeFromSuperview];
// and then go to another scene
LoadingScene* scene = [LoadingScene sceneWithTargetScene:TargetSceneEndExperienceScene];
[[CCDirector sharedDirector] replaceScene:scene];
}
那正是它謝謝你! – daidai