And*_*son 2 cocoa-touch objective-c ios
UIButton的几个属性本身并不具有动画效果.其中一个属性是contentHorizontalAlignment财产.在没有运气的情况下搜索SO后,我想出了下面的答案来解决"不可动画"的问题.
您应该layoutIfNeeded在更改对齐值后设置动画:
目标C:
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[UIView animateWithDuration:0.3 animations:^{
[self.view layoutIfNeeded];
}];
Run Code Online (Sandbox Code Playgroud)
Swift3:
button.contentHorizontalAlignment = .left
UIView.animate(withDuration: 0.3, animations: {
self.view.layoutIfNeeded()
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
440 次 |
| 最近记录: |