【发布时间】:2014-05-28 11:23:54
【问题描述】:
我有一些这样的 UIButton 类:
@implementation UIRoundButton
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self.layer setCornerRadius:self.frame.size.width/2];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self.layer setCornerRadius:self.frame.size.width/2];
}
return self;
}
- (void) layoutIfNeeded
{
[super layoutIfNeeded];
[self.layer setCornerRadius:self.frame.size.width/2];
}
因此它会创建圆形按钮并更改自动布局的角半径。
但我的问题是当我想做这样的动画时:
[UIView animateWithDuration:0.6 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.deleteButton.alpha = 1;
self.buttonHeight.constant = 40;
self.buttonWidth.constant = 40;
[self layoutIfNeeded];
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.6 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.deleteButton.alpha = 0;
self.buttonHeight.constant = 16;
self.buttonWidth.constant = 16;
[self layoutIfNeeded];
} completion:^(BOOL finished) {
}];
}];
所以我改变了这个按钮的宽度和高度。问题是拐角半径没有正确改变。为什么?它应该调用 layoutIfNeeded 方法并更改它。
马尔科
编辑:
这意味着在动画之前按钮的宽度和高度为 16。我动画为 40。但角落通过所有动画 8 像素。然后在结束动画上,我再次从宽度值 40 到宽度值 16 进行动画处理,现在所有动画的角半径为 20 px。就像它只会在动画结束时调用 layoutIfNeeded
【问题讨论】:
标签: ios xcode animation autolayout cornerradius