1
是否可以動畫UIButton的邊框厚度?動畫UIButton邊框厚度
我嘗試了以下方法,但我只是想在兩個厚度之間進行快速閃動,我試圖在兩者之間進行動畫處理。
//animate border thickness
UIButton *btn = _barButton;
CALayer *buttonLayer = [btn layer];
[buttonLayer setBorderWidth:0.0f];
[UIView animateWithDuration:1.0f animations:^{
[buttonLayer setBorderWidth:15.0f];
} completion:^(BOOL finished){
[UIView animateWithDuration:1.0f animations:^{
[buttonLayer setBorderWidth:2.5f];
} completion:nil];
}];
編輯:根據大衛H的建議,這可以用CABasicAnimation完成。
UIButton *btn = _barButtons;
CALayer *buttonLayer = [btn layer];
//animate border thickness
CABasicAnimation *animation = [CABasicAnimation animation];
animation.keyPath = @"borderWidth";
animation.fromValue = @0.0;
animation.toValue = @5.0;
animation.duration = 0.25;
[buttonLayer addAnimation:animation forKey:@"basic"];