需要帮助处理(解雇)objective-c (iphone) 中的 ImagePicker (相机)

发布于 11-26 04:04 字数 894 浏览 0 评论 0原文

我在忽略相机视图时遇到了一些问题。 我使用 UIImagePickerController 与此代码 -

-(void)viewDidAppear:(BOOL)animated{
UIImagePickerController *picker=[[UIImagePickerController alloc]init];
picker.delegate=self;
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls=NO;
[picker.cameraOverlayView addSubview:mirrorOverlay];
picker.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:picker animated:YES];
[picker release];}

我使用自定义按钮关闭相机并使用此代码将视图更改回我的主视图 -

-(IBAction)flipBack:(id)sender{
[self dismissModalViewControllerAnimated:YES];

我的问题是当我按下“视图翻转”按钮,然后返回并再次调用相机。 我找不到一种方法来消除相机和视图。

请帮忙。 谢谢, 阿米尔。


更新: 感谢您的帮助!我明白了! 我的问题是我正在使用相机的 nib 文件,当您想以委托上描述的不同方式使用相机时,您应该使用 View 而不是 nib。

所以我的代码是正确的,但位置和格式错误。 谢谢大家!

如果有人需要帮助,我会在这里提供帮助!

i have a little problem with dismissing my camera view.
im using the UIImagePickerController with this code-

-(void)viewDidAppear:(BOOL)animated{
UIImagePickerController *picker=[[UIImagePickerController alloc]init];
picker.delegate=self;
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls=NO;
[picker.cameraOverlayView addSubview:mirrorOverlay];
picker.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:picker animated:YES];
[picker release];}

im using a custom button to close the camera and change the view back to my main view using this code-

-(IBAction)flipBack:(id)sender{
[self dismissModalViewControllerAnimated:YES];

my problem is when im pressing the button the View flipout and then going back in and call the camera again.
i can't find a way to dismiss the camera and the view.

Please help.
Thanks,
Amir.


Update:
Thanks for the help ! i figure it out !
my problem was that i was working with nib files of the camera, and when you want to use the camera in different way that was described on the delegate you should use View and not nib.

so my code was correct but in the wrong place and format.
Thanks all !

if someone need help with it, I'm here to help back !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

橘香2024-12-03 04:04:10

您需要关闭选择器,从外观上看,您正在关闭呈现选择器的控制器。

-(IBAction)flipBack:(id)sender{
    [picker dismissModalViewControllerAnimated:YES];
}

在这种情况下,您需要保留对 picker 的引用(例如:添加 UIImagePicker *picker; 作为 viewcontroller 类的成员)。

you need to dismiss the picker, by the looks of it you're dismissing the controller that presents the picker.

-(IBAction)flipBack:(id)sender{
    [picker dismissModalViewControllerAnimated:YES];
}

You need to keep a reference to the picker in this case (e.g: add UIImagePicker *picker; as a member to your viewcontroller class).

筱武穆2024-12-03 04:04:10

看来您将代码放在错误的位置,因为每次您的 viewDidAppear 都会显示选择器,而不是您需要将图像选择器代码放在某个按钮单击上。然后您可以实现选择器的委托方法,如 imagePickerDidCancel 和 imagePickerDidFinishPickingMedia 来关闭选择器实现 imagePickerDidCancel或者如果您想要自定义取消方法,您的代码看起来不错。

It seems you put code at wrong place because every time your viewDidAppear the picker will be presented instead of this you need to put image picker code on some button click.Then you can implement picker's delegate method like imagePickerDidCancel and imagePickerDidFinishPickingMedia to dismiss the picker implement imagePickerDidCancel or if you want you custom cancel method your code looks fine.

在 iOS7 中,不推荐使用相机胶卷图像选择器呈现/关闭 ModalViewController。

要打开图像选择器,请使用:

[controller presentViewController:mediaUI animated:YES completion:nil]; // open image picker

要关闭或取消图像选择器,请使用:

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:nil]; // close image picker
}

有关详细信息,最好查看: https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Articles/Articles/PickinganItemfromthePhotoLibrary.html

In iOS7 present/dismiss ModalViewController is deprecated for Camera Roll image picker.

To open image picker use:

[controller presentViewController:mediaUI animated:YES completion:nil]; // open image picker

To close or cancel image picker use:

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:nil]; // close image picker
}

For more information best to look at: https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Articles/Articles/PickinganItemfromthePhotoLibrary.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文