UIImagepickerController [takepicture] 模态视图消失没有委托回调

发布于 2024-08-10 23:03:16 字数 2055 浏览 12 评论 0原文

更新:

此问题已得到解答。这是我自己的愚蠢,可能不值得再阅读这个问题。哈哈。

问题:

是的,我有这个 UIViewController(master) 子类,它有一个 UIImagepickerController(camera),它还有一个 UIView(overlayView)。 Master 将相机设置为仅使用自定义cameraOverlay、隐藏自定义控件等配置为相机的相机,

除了当我尝试以编程方式拍照之外,所有这些似乎都工作正常。发生的情况是,overlayView 调用 master,这会触发拍照,然后我听到快门声,光圈关闭,相机似乎自行关闭(我在代码中显然没有这样做),然后我的 viewDidAppear 被调用又是我的主人。

有人知道发生了什么事吗?

    -(void)viewDidLoad
{
    NSLog(@"loading the view");
    //if the camera is on the device
    if ( [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) 
    {
        //make one
        camera = [[UIImagePickerController alloc] init];
        //setup some settings that we need
        camera.sourceType = UIImagePickerControllerSourceTypeCamera;
        camera.showsCameraControls = NO;
        camera.navigationBarHidden = NO;
        camera.toolbarHidden = YES;
        camera.cameraViewTransform = CGAffineTransformScale(camera.cameraViewTransform, 1.03, 1.03);
        //show it
        overlayView = [[OverlayView alloc] initWithFrame:CGRectMake(0,0,320,480) withDelegate:self andController:self];
        camera.cameraOverlayView = overlayView;
            camerashowing=NO;

    }
    else 
    {
        alert = [[UIAlertView alloc] initWithTitle:@"No Camera Detected" message:@"The camera is broken or your device has no camera. Please close the application" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
    }
}

-(void)viewDidAppear:(BOOL)animated
{
  if (!cameraShowing)
  {
    NSLog(@"going to show camera");
    [self presentModalViewController:camera animated:NO];
    camerashowing = YES;
  }
}



 -(void)releaseShutter
  { 
    [overlayView toolbarShowWarning];
    NSLog(@"going to show camera: %@", self);
    [camera takePicture]; 

    }

经过人们在答案中的一些帮助建议后,我可以说相机没有被发布。

我还设法通过检查 viewDidAppear 方法中的 bool 值来阻止 exec_bad_access 再次调用 [presentmodal....] 。

我仍然遇到模态视图消失的问题,有什么帮助吗?哈哈?

Update:

This has been answered. It was my own stupidity, possibly not worth reading any more of this question. lol.

Question:

Right so i have this UIViewController(master) subclass, it has a UIImagepickerController(camera), it also has a UIView(overlayView). Master setups the camera to be configured as a camera only with a custom cameraOverlay, hiding the custom controls e.t.c.

All appears to work fine apart from when i try to programatically take a picture. What happens is the overlayView calls the master and this triggers the take picture, then i hear the shutter sound and the iris closes, the camera appears to dismiss itself (i am defiantly not doing this in my code) and then my viewDidAppear gets called in my master again.

Anybody have any idea whats going on ?

    -(void)viewDidLoad
{
    NSLog(@"loading the view");
    //if the camera is on the device
    if ( [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) 
    {
        //make one
        camera = [[UIImagePickerController alloc] init];
        //setup some settings that we need
        camera.sourceType = UIImagePickerControllerSourceTypeCamera;
        camera.showsCameraControls = NO;
        camera.navigationBarHidden = NO;
        camera.toolbarHidden = YES;
        camera.cameraViewTransform = CGAffineTransformScale(camera.cameraViewTransform, 1.03, 1.03);
        //show it
        overlayView = [[OverlayView alloc] initWithFrame:CGRectMake(0,0,320,480) withDelegate:self andController:self];
        camera.cameraOverlayView = overlayView;
            camerashowing=NO;

    }
    else 
    {
        alert = [[UIAlertView alloc] initWithTitle:@"No Camera Detected" message:@"The camera is broken or your device has no camera. Please close the application" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
    }
}

-(void)viewDidAppear:(BOOL)animated
{
  if (!cameraShowing)
  {
    NSLog(@"going to show camera");
    [self presentModalViewController:camera animated:NO];
    camerashowing = YES;
  }
}



 -(void)releaseShutter
  { 
    [overlayView toolbarShowWarning];
    NSLog(@"going to show camera: %@", self);
    [camera takePicture]; 

    }

After some help advice from people in the answers i can say that the camera is not being released.

I have also managed to stop the exec_bad_access by stopping it from calling [presentmodal....] for a second time by checking a bool value in the viewDidAppear Method.

I still have the issue where the modal view disapears, any help, again lol ??

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

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

发布评论

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

评论(3

唯憾梦倾城 2024-08-17 23:03:16

我认为您缺少 camera.delegate = self;

I think you're missing a camera.delegate = self;

夜灵血窟げ 2024-08-17 23:03:16

对于任何 EXC_BAD_ACCESS 错误,您通常尝试向已释放的对象发送消息。追踪这些的最佳方法是使用NSZombieEnabled

这是通过从不真正释放一个对象,而是通过将其包装为“僵尸”并在其中设置一个标志来表示它通常会被释放来实现的。这样,如果您尝试再次访问它,它仍然知道您犯错误之前的情况,并且有了这一点信息,您通常可以回溯以查看问题所在。

当调试器有时会放弃任何有用的信息时,它在后台线程中尤其有用。

非常重要的是要注意,但是,您需要 100% 确保这仅在您的调试代码中,而不是在您的分发代码中。因为没有任何东西被发布,所以你的应用程序将会泄漏、泄漏、泄漏。为了提醒我这样做,我将此日志放入我的应用程序委托中:

if(getenv("NSZombieEnabled") || getenv("NSAutoreleaseFreedObjectCheckEnabled"))
  NSLog(@"NSZombieEnabled/NSAutoreleaseFreedObjectCheckEnabled enabled!");

如果您需要帮助找到确切的行,请执行构建和调试 (CMD-Y),而不是构建和运行 (CMD-R)。当应用程序崩溃时,调试器将准确地显示哪一行,并结合 NSZombieEnabled,您应该能够找出确切的原因。

For any EXC_BAD_ACCESS errors, you are usually trying to send a message to a released object. The BEST way to track these down is use NSZombieEnabled.

This works by never actually releasing an object, but by wrapping it up as a "zombie" and setting a flag inside it that says it normally would have been released. This way, if you try to access it again, it still know what it was before you made the error, and with this little bit of information, you can usually backtrack to see what the issue was.

It especially helps in background threads when the Debugger sometimes craps out on any useful information.

VERY IMPORTANT TO NOTE however, is that you need to 100% make sure this is only in your debug code and not your distribution code. Because nothing is ever released, your app will leak and leak and leak. To remind me to do this, I put this log in my appdelegate:

if(getenv("NSZombieEnabled") || getenv("NSAutoreleaseFreedObjectCheckEnabled"))
  NSLog(@"NSZombieEnabled/NSAutoreleaseFreedObjectCheckEnabled enabled!");

If you need help finding the exact line, Do a Build-and-Debug (CMD-Y) instead of a Build-and-Run (CMD-R). When the app crashes, the debugger will show you exactly which line and in combination with NSZombieEnabled, you should be able to find out exactly why.

哀由 2024-08-17 23:03:16

在尝试显示它之前检查camera成员变量的值:

NSLog(@"going to show camera: %@", camera);

我怀疑它可能在某个地方被释放,但因为coneybeare NSZombieEnabled会让你追踪它。

Check the value of the camera member variable before you try and display it:

NSLog(@"going to show camera: %@", camera);

I suspect it might be being released somewhere, but as coneybeare NSZombieEnabled will let you track it down.

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