-1

我希望能够在我正在创建的游戏应用程序中打开相机。该游戏应用程序是使用 iOS Objective C 和 HTML 构建的。我想知道在本机端使用哪些功能,以及在 HTML 和 JS 端使用哪些其他功能?

我知道我必须使用 UIImagePickerController,我不完全明白有人可以帮忙吗?

4

1 回答 1

1

在 iPad 上,您必须使用UIImagePickerController对象和委托,并UIPopoverController在 popover 中显示选择器。我的应用程序中的一些代码。我用它从库或相机中加载图像。

- (IBAction)choosePhoto:(id)sender {

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;

if ([sender tag] == FROM_LIBRARY) {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    else {
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    }
}
else if ([sender tag] == FROM_CAMERA) {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    }
    else {
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    }
}

pop = [[UIPopoverController alloc] initWithContentViewController:picker];
pop.delegate = self;
[pop presentPopoverFromRect:CGRectMake(234, 372, 300, 300) inView:self.view permittedArrowDirections:0 animated:YES];

[self hideMenu];
}

那么你必须使用UIImagePickerControllerDelegate方法-(void)imagePickerController:(UIImagePickerController *)pk didFinishPickingMediaWithInfo:(NSDictionary *)info来获取图像。

一切都在这里http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

于 2012-11-04T23:26:54.977 回答