您的位置:首页 > 移动开发 > Cocos引擎

关于cocos2d调用相册及摄像头问题

2013-08-08 22:51 387 查看
调用摄像头或相册需要用到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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  cocos2d-x