gpt4 book ai didi

iphone - UIButton 通过动画调整大小

转载 作者:行者123 更新时间:2023-12-03 18:23:06 25 4
gpt4 key购买 nike

我正在创建一个菜单,我想按钮“弹出”在屏幕上。基本上我想从 0px 尺寸开始,然后达到按钮的完整尺寸。如果我愿意的话,我可以为 Alpha 和位置设置动画,但无法确定尺寸,我认为这是因为它是按钮上的图像。

如果我执行 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来尝试为其提供上下文或其他内容,但无济于事。

为您的帮助干杯。

最佳答案

您可以尝试使用以下代码吗?

button.transform = CGAffineTransformMakeScale(1.5,1.5);
button.alpha = 0.0f;

[UIView beginAnimations:@"button" context:nil];
[UIView setAnimationDuration:1];
button.transform = CGAffineTransformMakeScale(1,1);
button.alpha = 1.0f;
[UIView commitAnimations];

您的按钮一开始应稍大,然后缩小。如果缩放正确,只需调整前后的比例因子以适应即可。

关于iphone - UIButton 通过动画调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3145645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com