猴子原创,欢迎转载。转载请注明出处,谢谢。
原文地址:http://blog.csdn.net/yanghuiliu/article/details/7016363
一直纠结如何获取iphone的摄像头,研究了哈发现其实完全可以的。首先通过UIImagePickerController获取摄像头,然后使用CCDirector的addSubView添加子视图。虽然基本实现了,但是还是不是我想要的结果,暂时记录一笔,日后完善。
看看代码(这是OC的代码):
-(id) init
{
if( (self=[super init] )) {
CCMenuItem *menuItem1 = [CCMenuItemImage itemFromNormalImage:@"phone_nor.png"
selectedImage:@"phone_pre.png"
target:self
selector:@selector(getPhoto:)];
CCMenu *menu = [CCMenu menuWithItems:menuItem1,nil];
[menu setPosition(40, 40)];
[self addChild:menu];
}
return self;
}
-(void)getPhoto:(UIImagePickerControllerSourceType)sourceType{
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.wantsFullScreenLayout = YES;
[picker presentModalViewController:picker animated:YES];
[[[CCDirector sharedDirector] openGLView] addSubview:picker.view];
}