调用摄像头或相册需要用到UIImagePickerController这个类,
当然大家首先会想到以模态对话框的形式弹出相册,
但是注意这个类UIImagePickerController只在iphone平台下支持
presentModalViewController
的形式打开相册,且方向为竖屏,如果你开发横屏游戏可能会觉得不太好
关于ipad下,你需要用UIPopoverController来显示相册库,
这是你需要这样调用
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.wantsFullScreenLayout = YES;
UIPopoverController * photoPop=[[UIPopoverController alloc] initWithContentViewController:picker];
[photoPop presentPopoverFromRect:CGRectMake(inView.frame.size.width, inView.frame.size.height/2, 0, 0) inView:inView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[picker release];
这样就OK了,inView,关于这个对象,可以为openglView,也可以为加入到openglView中的任何继承自UIVIew的控件
调用摄像头与此类似
另外,为了适配ios6,你还需要加入以下委托方法
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAll;
}