我正在创建一个应用程序,它从 iphone 相机捕获图像并将其显示在创建的应用程序中我阅读了 ios 开发人员库中的一些文章并将此代码编写在 .m 文件中
- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate {
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
// Displays a control that allows the user to choose picture or
// movie capture, if both are available:
cameraUI.mediaTypes =
[UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypeCamera];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
cameraUI.allowsEditing = NO;
cameraUI.delegate = delegate;
[controller presentModalViewController: cameraUI animated: YES];
return YES;
}
还创建了一个与此代码链接的按钮,它调用此函数但控件不传递给上述函数
- (IBAction) showCameraUI {
[self startCameraControllerFromViewController: self
usingDelegate: self];
}
而且我也不知道这段代码是否有效
有人有更好的主意吗。谢谢,阿伦。