我正在创建一个菜单,我希望按钮在屏幕上 "弹出"。基本上,我想从 0px 的尺寸开始,然后到达按钮的完整尺寸。如果需要的话,我可以动画化 alpha 和位置,但无法调整尺寸,我认为这是因为按钮上有一张图片。
如果我使用 UIButtonTypeRoundRect,您可以看到图像后面的按钮被动画化了,但该图像是静态的。
如果我使用 UIButtonTypeRoundRect,您可以看到图像后面的按钮被动画化了,但该图像是静态的。
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:@"settings.png"] forState:UIControlStateNormal];
button.frame = CGRectMake(20, 20, 0, 0);
button.alpha = 0;
[self.view addSubview:button];
CGRect frame = button.frame;
[UIView beginAnimations:@"button" context:nil];
[UIView setAnimationDuration:1];
button.alpha = 1;
frame.size.width += 53;
frame.size.height += 53;
button.frame = frame;
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
Alpha已经生效了,但是调整大小没有生效。我也尝试使用stretchableImageWithLeftCapWidth来为其提供上下文或其他内容,但无济于事。
感谢你的帮助。