UIImagePickerController相机源问题

发布于 2024-10-21 17:55:46 字数 857 浏览 5 评论 0原文

好的,这是我编写的用于在相机源中显示 UIImagePickerController 的代码。我刚刚在属性的标头中声明了 myPhotopicker 并保留它。综合在主代码文件中。然后调用选择器,我编写了下面的代码:

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        if (myPhotopicker==nil) { 
            myPhotopicker = [[UIImagePickerController alloc] init];
            myPhotopicker.delegate = self; 
        }// create once!

        myPhotopicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self presentModalViewController:myPhotopicker animated:NO];
}

调用它时,应用程序发生了一些奇怪的事情。

  1. 有时,当后台运行多个应用程序时(iPhone4),应用程序会无法加载相机并导致应用程序崩溃。虽然它可以毫无问题地加载CameraRoll/PhotoAlbums。

  2. 如果相机视图能够加载(当后台运行的应用程序较少时),点击相机视图上的“取消”按钮会导致应用程序自行重新启动(其中快速显示 Default.png 图像,然后返回)到主页 - 就像我们启动应用程序时一样)。

我一直在试图解决这个问题,但不知道该怎么做...请帮助..谢谢。

Ok here is the code that I wrote to display the UIImagePickerController in the camera source. I just declared the myPhotopicker in the header for the property and retain it. Synthesized it in the main code file. Then calling the picker I wrote the code below:

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        if (myPhotopicker==nil) { 
            myPhotopicker = [[UIImagePickerController alloc] init];
            myPhotopicker.delegate = self; 
        }// create once!

        myPhotopicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self presentModalViewController:myPhotopicker animated:NO];
}

Upon calling it, there are a few things that is weird happening to the app.

  1. Sometimes, when there are many apps running in the background (iPhone4), the app would fail to load the camera and crash the app. Though it will load CameraRoll/PhotoAlbums without problem.

  2. If the camera view is able to load (when there are less apps running in the background), tapping the Cancel button on the camera view results in the app rebooting itself (where the Default.png image is shown quickly, and back to the main page - like when we started the app).

I have been trying to figure out this problem, but not sure what to do... pls help.. Thanks.

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

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

发布评论

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

评论(2

じ违心 2024-10-28 17:55:46

这是图像选择器控件的完整代码,也可以尝试找到解决方案。这里。

http://www.icodeblog.com/2009/07/28/getting-images-from-the-iphone-photo-library-or-camera-using-uiimagepickercontroller/

问候,

Shyam Parmar

here is the complete code of image pickercontrol try too find solu. here.

http://www.icodeblog.com/2009/07/28/getting-images-from-the-iphone-photo-library-or-camera-using-uiimagepickercontroller/

Regards,

Shyam Parmar

一身软味 2024-10-28 17:55:46

尝试每次创建和释放,而不是“创建一次”逻辑。

if ([UIImagePickerController  isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
     myPhotopicker = [[UIImagePickerController alloc] init];
     myPhotopicker.delegate = self;
     myPhotopicker.sourceType = UIImagePickerControllerSourceTypeCamera;
     [self presentModalViewController:myPhotopicker animated:NO];
     [myPhotopicker release];
}

您还应该实现委托,以便在模式视图控制器被关闭时从视图中删除它(如果您还没有这样做)。

您还应该检查当前类是否符合 UINavigationConrollerDelegate 协议。

Rather than your 'create once' logic try creating and releasing each time.

if ([UIImagePickerController  isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
     myPhotopicker = [[UIImagePickerController alloc] init];
     myPhotopicker.delegate = self;
     myPhotopicker.sourceType = UIImagePickerControllerSourceTypeCamera;
     [self presentModalViewController:myPhotopicker animated:NO];
     [myPhotopicker release];
}

You should also implement the delegate to remove the modal view controller from view when it is dismissed (if you haven't already).

You should also check that the current class conforms to the UINavigationConrollerDelegate protocol.

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