I have some class for UIButton like this :
@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];
}
So it create rounded button and change corner radius for auto layout.
But my problem is when I want to do animation like this :
[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) {
}];
}];
So I change width and height for this button. The problem is that corner radius does not change properly. Why? It should call layoutIfNeeded method and change it.
Marko
EDIT :
This means that before animation the button has width and height 16. I animate to be 40. But the corners are through all animation 8 px. Then on the end animations I animate again from width value 40 to width value 16, now the corner radius is 20 px through all animation. Like it would call layoutIfNeeded onelly at the end of animations