In a UIView animation for a view, you can animate its subviews being laid out by including UIViewAnimationOptionLayoutSubviews
in the options parameter
You might have found the answer already, but I also faced similar problems recently, since solved it, I will post the answer.
In - layoutSubViews
method, you can get current UIView
animation as backing layer's CAAnimation
with - animationForKey:
method.
Using this, You can implement - layoutSubviews
like:
- (void)layoutSubviews {
[super layoutSubviews];
// get current animation for bounds
CAAnimation *anim = [self.layer animationForKey:@"bounds"];
[CATransaction begin];
if(anim) {
// animating, apply same duration and timing function.
[CATransaction setAnimationDuration:anim.duration];
[CATransaction setAnimationTimingFunction:anim.timingFunction];
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
[self.borderLayer addAnimation:pathAnimation forKey:@"path"];
}
else {
// not animating, we should disable implicit animations.
[CATransaction disableActions];
}
self.borderLayer.path = [UIBezierPath bezierPathWithRect:self.bounds].CGPath;
self.borderLayer.frame = self.bounds;
[CATransaction commit];
}