cocos2d 3.x CCButton设置精灵帧图像失真并且回调/阻止不起作用

我需要设置一个按钮的精灵框架。

当我使用构造函数时它正在工作:

CCSprite *sprite = [CCSprite spriteWithImageNamed:@"but.png"]; CCButton *button = [CCButton buttonWithTitle:@"" spriteFrame:sprite.spriteFrame]; [button setBlock:^(id sender){...}] 

在此处输入图像描述

但是当我需要在之后设置精灵框架时,

  CCButton *button = [CCButton buttonWithTitle:@""]; button.background.spriteFrame = sprite.spriteFrame; 

或这个

  [button setBackgroundSpriteFrame:sprite.spriteFrame forState:CCControlStateNormal]; 

两者都不工作,结果是图像失真,并且不调用回调函数或块。

在此处输入图像描述

您好我有同样的问题,并找到了解决方案。 就这样做:

 CCSpriteFrame *spriteFrame = [CCSpriteFrame frameWithImageNamed:@"Icon-Small.png"]; button = [CCButton buttonWithTitle:@"" spriteFrame:spriteFrame]; 

奇迹般有效!