显示并关闭模态视图控制器 UIImagePickerController 之后,我的 Cocos2d iPhone 应用程序不再看到多次触摸

发布于 2024-08-01 17:53:05 字数 1765 浏览 3 评论 0原文

我有一个应用程序,我在其中显示照片选择器(UIImagePickerController),但在用户关闭后,只有单次触摸才起作用。 我想我知道问题的根源,但我不知道如何解决它...在显示模式对话框之前,触摸期间的堆栈如下所示:

...
#3  0x00074de0 in -[EAGLView touchesBegan:withEvent:] at EAGLView.m:289
#4  0x30910f33 in -[UIWindow _sendTouchesForEvent:]
...

但是在显示并删除模式对话框之后,堆栈有这两个神秘的forwardMethod2调用:

...
#3  0x00074de0 in -[EAGLView touchesBegan:withEvent:] at EAGLView.m:289
#4  0x3098dc95 in forwardMethod2
#5  0x3098dc95 in forwardMethod2
#6  0x30910f33 in -[UIWindow _sendTouchesForEvent:]
...

这是我用来显示和删除UIImagePickerController的代码: 笔记: 1. pickerViewController是该类的成员,扩展了UIViewController) 2. Director 来自 Cocos2D,只包含一个直接附加在根窗口中的视图,称为 openGLView,这就是为什么我创建了一个 UIViewController 来容纳我的图像选择器。

-(void)choosePhoto: (id)sender{
    UIImagePickerController *imagePickerController = pickerViewController.imagePickerController;
    imagePickerController.delegate = self;
    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePickerController.allowsImageEditing = YES;

    UIView *theView = [[Director sharedDirector] openGLView];
    UIView *pickerViewControllerView = pickerViewController.view;
    [theView addSubview:pickerViewControllerView];
    [pickerViewController presentModalViewController:imagePickerController animated:YES];
}

以及关闭对话框的代码:

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)imagePickerController
{
    // Dismiss the image selection
    [pickerViewController dismissModalViewControllerAnimated:YES];
    [pickerViewController.view removeFromSuperview];

    // HERE... IS THERE MORE WORK TO BE DONE TO COMPLETELY REMOVE THE PICKER VIEW????
}

在清理选择器视图时一定缺少一些东西...非常感谢帮助:)

I have an app where I display the photo chooser (UIImagePickerController) but after the user dismisses it only single touches are working. And I think I know the root of the issue, but I don't know how to solve it... Before I show the modal dialog the stack during a touch is as follows:

...
#3  0x00074de0 in -[EAGLView touchesBegan:withEvent:] at EAGLView.m:289
#4  0x30910f33 in -[UIWindow _sendTouchesForEvent:]
...

But after showing and then removing the modal dialog the stack has these two mysterious forwardMethod2 calls:

...
#3  0x00074de0 in -[EAGLView touchesBegan:withEvent:] at EAGLView.m:289
#4  0x3098dc95 in forwardMethod2
#5  0x3098dc95 in forwardMethod2
#6  0x30910f33 in -[UIWindow _sendTouchesForEvent:]
...

Here is the code I use to display and remove the UIImagePickerController:
Notes:
1. pickerViewController is a member of this class that extends UIViewController)
2. Director is from Cocos2D and contains only a single view attached directly in the root window called openGLView, which is why I made a UIViewController to house my image picker.

-(void)choosePhoto: (id)sender{
    UIImagePickerController *imagePickerController = pickerViewController.imagePickerController;
    imagePickerController.delegate = self;
    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePickerController.allowsImageEditing = YES;

    UIView *theView = [[Director sharedDirector] openGLView];
    UIView *pickerViewControllerView = pickerViewController.view;
    [theView addSubview:pickerViewControllerView];
    [pickerViewController presentModalViewController:imagePickerController animated:YES];
}

And the code to dismiss the dialog:

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)imagePickerController
{
    // Dismiss the image selection
    [pickerViewController dismissModalViewControllerAnimated:YES];
    [pickerViewController.view removeFromSuperview];

    // HERE... IS THERE MORE WORK TO BE DONE TO COMPLETELY REMOVE THE PICKER VIEW????
}

There must be something I'm missing in cleaning up the picker view... Help is greatly appreciated :)

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

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

发布评论

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

评论(2

风吹雪碎 2024-08-08 17:53:05

从根窗口向下调查视图层次结构后,我发现在关闭照片选择器后,我的 viewController 的视图被添加为 UITransitionView 下的子视图,因此解决方案是删除 viewController 的视图的超级视图:

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)imagePickerController
{
    // Dismiss the image selection
    [pickerViewController dismissModalViewControllerAnimated:YES];
    [pickerViewController.view.superview removeFromSuperview];
}

After investigating the view hierarchy from the root window down I have found that after dismissing the Photo chooser that my viewController's view was getting added as a child under a UITransitionView so the solution is to remove the superview of my viewController's view instead:

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)imagePickerController
{
    // Dismiss the image selection
    [pickerViewController dismissModalViewControllerAnimated:YES];
    [pickerViewController.view.superview removeFromSuperview];
}
你怎么这么可爱啊 2024-08-08 17:53:05

我注意到 CJ Hanson 的解决方案适用于 iPhone:

[pickerViewController.view.superview removeFromSuperview];

但不适用于 iPad。 正常方式:

[pickerViewController.view removeFromSuperview];

在 iPad 上工作。 我现在只是给两者打电话,似乎工作正常:

[pickerViewController.view removeFromSuperview];
[pickerViewController.view.superview removeFromSuperview];

也许有更多知识的人可以澄清为什么需要这样做?

I've noticed that CJ Hanson's solution works for me on iPhones:

[pickerViewController.view.superview removeFromSuperview];

but not on iPads. The normal way:

[pickerViewController.view removeFromSuperview];

works on the iPad. I just call both at the moment and it seems to work ok:

[pickerViewController.view removeFromSuperview];
[pickerViewController.view.superview removeFromSuperview];

Maybe someone with more knowledge can clarify why this is needed?

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