All the touch cancelled after show the UIView (iOS)

All the touch cancelled after show the UIView (iOS)
0

Please help to find the problem of all the touch failed after I call the gallery/camera, and below is the class.

Call Here:

void AppBubbleChangeLayer::onTouchMask()
{
[iOSImagePicker TakePhoto: this ];
this ->onExit();
}

iOSImagePicker.h

#ifndef iOSImagePicker_h
#define iOSImagePicker_h
#import <Foundation/Foundation.h>
#include “cocos2d.h”
#include “AppBubbleChangeLayer.h”

@interface iOSImagePicker :UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate> {

AppBubbleChangeLayer* m_ChangeLayer;

}

+(iOSImagePicker*)TakePhoto:(AppBubbleChangeLayer *) layer;
-( void )OpenCamera;
-( void )saveTOAlbum;
@end

#endif

iOSImagePicker.mm

#import <Foundation/Foundation.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import <Photos/Photos.h>
#import “iOSImagePicker.h”
#import “AppDelegate.h”

#include “cocos2d.h”

@implementation iOSImagePicker

Sprite* getSpriteFromUIImage(UIImage *photo)
{
NSLog(@“width =%f, height =%f”, [photo size].width, [photo size].height);

std::string imagPath = FileUtils::getInstance()->getWritablePath();
imagPath.append(kSaveTmpPhotoName);

Texture2D* objTexture2D = new Texture2D();
Image* image = new Image();

image->initWithImageFile(imagPath);
objTexture2D->initWithData(image->getData(),image->getDataLen(),
                           Texture2D::PixelFormat::RGB888,image->getWidth(),image->getHeight(),
                           cocos2d::Size(image->getWidth(),image->getHeight()));

Sprite *sprit = Sprite::createWithTexture(objTexture2D);

cocos2d::log("Sprite Size :%f :%f ",sprit->getContentSize().width , sprit->getContentSize().height);

return sprit;

}

+(iOSImagePicker*) TakePhoto:(AppBubbleChangeLayer*) layer
{

UIWindow *window = [[UIApplication sharedApplication] keyWindow];
iOSImagePicker *viewController = [[iOSImagePicker alloc] init];
viewController->m_ChangeLayer = layer;
[window addSubview:viewController.view];
[viewController OpenCamera];

return viewController;

}
-(void) OpenCamera
{
NSLog(@“啓動相機”);
UIImagePickerController *picker= [[UIImagePickerController alloc] init];
picker.delegate = self;

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
    else
    {
        NSLog(@"模擬器無法打開相機");
    }

[self presentViewController:picker animated:YES completion:nil];

}

  • (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
    NSLog(@“拍照”);

    UIImage *originImage = [info objectForKey:UIImagePickerControllerOriginalImage];
    NSArray paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString documentsDirectory = [paths objectAtIndex:0];
    NSString
    path = [documentsDirectory stringByAppendingPathComponent:@kSaveTmpPhotoName];
    NSLog(@“The image path is-%@”,path);
    NSData
    data = UIImagePNGRepresentation(originImage);
    [data writeToFile:path atomically:YES];

    auto photo = getSpriteFromUIImage(originImage);
    m_ChangeLayer->importPhoto(photo);

    [picker dismissViewControllerAnimated:true completion:nil];
    [self.view removeFromSuperview];
    }

//取消

  • (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    NSLog(@“取消”);
    m_ChangeLayer->onEnter();

    [picker dismissViewControllerAnimated:true completion:nil];
    [self.view removeFromSuperview];
    }

-(void) dealloc
{
m_ChangeLayer = NULL;

[self release];
[super dealloc];

}

@end