Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在后台线程上调用函数时,具有透明图像的精灵显示为白色框_Iphone_Objective C_Cocos2d Iphone - Fatal编程技术网

Iphone 在后台线程上调用函数时,具有透明图像的精灵显示为白色框

Iphone 在后台线程上调用函数时,具有透明图像的精灵显示为白色框,iphone,objective-c,cocos2d-iphone,Iphone,Objective C,Cocos2d Iphone,我正在检测面部特征并显示位置,我正在通过透明图像创建精灵,如果我调用函数在主线程上添加精灵,精灵显示正确,但当我在背景线程或除主线程外的任何其他线程上调用此函数时,它显示的是白色框。下面我上传了屏幕截图和代码片段 - (id)init{ if( (self=[super init])) { [self addBackImageAndControls]; } return self; } -(void)addBackImageAndControls{

我正在检测面部特征并显示位置,我正在通过透明图像创建精灵,如果我调用函数在主线程上添加精灵,精灵显示正确,但当我在背景线程或除主线程外的任何其他线程上调用此函数时,它显示的是白色框。下面我上传了屏幕截图和代码片段

- (id)init{

       if( (self=[super init])) {

      [self addBackImageAndControls];
  }
return self;
 }

-(void)addBackImageAndControls{

    UIImage *scalledImage =[originalImage1 scaleToSize:CGSizeMake(320, 480)];
    texture2D =[[CCTexture2D alloc] initWithImage:originalImage1];

    [self body_init];

    self.isTouchEnabled = YES;

    CCMenuItem *done = [CCMenuItemFont itemFromString:@"Done" block:^(id sender) {[self done];}];
    done.position = ccp(40, 60);
    CCMenu *starMenu = [CCMenu menuWithItems:done, nil];//
    starMenu.position =CGPointZero;
    [self addChild:starMenu z:0 tag:125];

    //[self callFunc:scalledImage];

   [NSThread detachNewThreadSelector:@selector(callFunc:) toTarget:self withObject:scalledImage];

}

-(void)done{

  md.LipRect =  [self lipRect];

  [self removeAllChildrenWithCleanup:YES];

   CCMenuItem *item1 = [CCMenuItemFont itemFromString:@"One" block:^(id sender)
      {[self sizeOne];}];
   item1.position = ccp(40, 40);

  CCMenuItem *item2 = [CCMenuItemFont itemFromString:@"Two" block:^(id sender)
    {[self sizeTwo];}];
  item2.position = ccp(110, 40);

  CCMenuItem *item3 = [CCMenuItemFont itemFromString:@"Three" block:^(id sender)
  {[self sizeThree];}];
  item3.position = ccp(180, 40);

  CCMenu *starMenu = [CCMenu menuWithItems:item1,item2,item3, nil];//
  starMenu.position =CGPointZero;
  [self addChild:starMenu];

}

 -(void)callFunc:(UIImage*)image{


   [self opencvFaceDetect:image];
   [self opencvEyeDetect:image];
   [self opencvNoseDetect:image];

   [self LipsEffect];
}


如果要更新UI,则必须在主线程上完成。按如下方式包装UI更新:

dispatch_async(dispatch_get_main_queue(), ^{
    // UI here
});