After displaying and dismissing the Modal View Controller UIImagePickerController my Cocos2d iPhone app doesn't see multiple touches anymore

你离开我真会死。 提交于 2019-12-08 00:13:43

问题


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 :)


回答1:


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];
}



回答2:


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?



来源:https://stackoverflow.com/questions/1247992/after-displaying-and-dismissing-the-modal-view-controller-uiimagepickercontrolle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!