0

在 iOS7 上,我需要生成一个横向增长的按钮动画(仅在一侧)。为了达到这个效果,我尝试了缩放和平移的组合,但问题是缩放也会影响边框的大小,这不是我想要的。

在这个例子中,在将按钮的长度加倍后,侧边框的宽度也加倍:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(100, 100, 100, 100)];
[[button layer] setBorderWidth:2.0f];
[[button layer] setBorderColor:[UIColor blackColor].CGColor];

[UIView beginAnimations:@"button" context:nil];
[UIView setAnimationDuration:1];

button.transform = CGAffineTransformConcat( CGAffineTransformMakeScale(2,1), CGAffineTransformTranslate(button.transform, 50, 0));

button.alpha = 1.0f;
[UIView commitAnimations];
[self.view addSubview:button];

我想知道是否有一个聪明的解决方案可以在不使用 CGAffine 转换的情况下实现这种效果。

4

2 回答 2

1

您可以borderWidth使用其他属性为按钮设置动画,它是可动画的。祝你好运!

于 2013-10-01T06:17:36.620 回答
0
UIImage *originalImage = [UIImage imageNamed:@"myImage.png"];
UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
UIImage *stretchableImage = [originalImage resizableImageWithCapInsets:insets];
[myButton setBackgroundImage:stretchableImage forState:UIControlStateNormal];
// the image will be stretched to fill the button, if you resize it.

UIEdgeInsets 结构中的值决定了您不想被拉伸的边距。

从这里回答

于 2013-10-01T08:16:26.810 回答