Cocoa touch 可拉伸按钮图像的大小是否可以在Cocoa Touch中设置动画?

Cocoa touch 可拉伸按钮图像的大小是否可以在Cocoa Touch中设置动画?,cocoa-touch,core-animation,Cocoa Touch,Core Animation,我正在创建一个UIButton,它具有一个可拉伸的图像,其宽度为LeftCapWidth:topCapHeight: 我希望通过核心动画平滑地更改其大小,如下所示: float shrinkFactor = 0.2; NSTimeInterval slowSpeed = 5.0; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:slowSpeed]; UIButton *thisButton = (

我正在创建一个UIButton,它具有一个可拉伸的图像,其宽度为LeftCapWidth:topCapHeight:

我希望通过核心动画平滑地更改其大小,如下所示:

float shrinkFactor = 0.2;
NSTimeInterval slowSpeed = 5.0;

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:slowSpeed];

UIButton *thisButton = (UIButton *)[self.view viewWithTag:2];
thisButton.frame = CGRectMake(thisButton.frame.origin.x, thisButton.frame.origin.y, buttonStretchedWidth * shrinkFactor, thisButton.frame.size.height);

[UIView commitAnimations];
按钮图像大小不会设置动画,它只是捕捉到新的大小

当我使按钮的背景色可见时,我看到帧本身正确地设置了动画


是我遗漏了什么,还是图像拉伸无法设置动画?

我一直无法使图像拉伸不断更新。尝试将图像拆分为大写和中间区域,并使用相应的
自动重设网格任务集创建八个或九个
UIImageView
子视图。例如,右上角视图应具有
uiviewautoresizingflexibleftmargin | UIViewAutoresizingFlexibleBottomMargin
,下中视图(拉伸)应具有
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin
,等等。在iPhone操作系统上,一旦创建了视图,它们的价格就相当便宜,所以我认为,除非你同时制作六个按钮的动画,否则你不会看到性能的提升。尽管合成非不透明视图非常昂贵,但请确保尽可能使其不透明