gpt4 book ai didi

ios - 如何动画化 UIButton 内容对齐的变化

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:01:55 25 4
gpt4 key购买 nike

UIButton 的一些属性本身并不是可动画的。其中一个属性是 contentHorizo​​ntalAlignment 属性。在没有运气的情况下搜索 SO 之后,我想出了下面的答案来解决“不可动画”的问题。

最佳答案

您应该在更改对齐值后为 layoutIfNeeded 设置动画:

Objective-C :

button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[UIView animateWithDuration:0.3 animations:^{
[self.view layoutIfNeeded];
}];

Swift3:

button.contentHorizontalAlignment = .left
UIView.animate(withDuration: 0.3, animations: {
self.view.layoutIfNeeded()
})

关于ios - 如何动画化 UIButton 内容对齐的变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24871077/

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