Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.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
Ios cocos2d 3.x CCButton设置精灵帧图像扭曲和回调/块不工作_Ios_Iphone_Cocos2d Iphone - Fatal编程技术网

Ios cocos2d 3.x CCButton设置精灵帧图像扭曲和回调/块不工作

Ios cocos2d 3.x CCButton设置精灵帧图像扭曲和回调/块不工作,ios,iphone,cocos2d-iphone,Ios,Iphone,Cocos2d Iphone,我需要设置一个按钮的精灵框架 当我使用构造函数时,它正在工作: CCSprite *sprite = [CCSprite spriteWithImageNamed:@"but.png"]; CCButton *button = [CCButton buttonWithTitle:@"" spriteFrame:sprite.spriteFrame]; [button setBlock:^(id sender){...}] 但是当我以后需要设置精灵框架时 CCB

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

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

    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];
工作起来很有魅力