这个问题我已经遇到过好几次了,但是我在任何地方都找不到确切的答案。
我想为 UIButton 的宽度变化设置动画,类似于在 App Store 中按下 FREE 按钮时它会变为 INSTALL 时的效果。触摸后,按钮会展开但不会移动。在应用商店中,按钮只是向左扩展:我希望我的按钮向两个方向扩展。
我试过将 button.frame = ... 或 button.bounds = ... 包装在 [UIView beginAnimations:context:]
block 中,但这不起作用,即使我也将中心设置在 block 内。不管我做什么,按钮似乎只是动画到一个新的位置,然后捕捉到新的宽度。我在这里遗漏了什么吗?
作为附录,谷歌搜索发现很多人都有类似的问题,而且他们往往只是放弃他们试图做的任何动画,这对我来说似乎很奇怪。这应该是一个简单的解决方案,对吧? :)
谢谢!
最佳答案
我刚刚测试过它,它运行良好:
// Button setup (to keep text central during animation)
button.titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
// Animate
[UIView beginAnimations:nil context:nil];
CGRect old = button.frame;
CGFloat diff = 60;
button.frame = CGRectMake(old.origin.x-diff/2.0, old.origin.y, old.size.width+diff, old.size.height);
[UIView commitAnimations];
关于iphone - 使用固定中心点为 UIButton 中的宽度变化设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4198866/