У меня есть UIViewController на UINavigationController со специальным NSObject, который выполняет некоторые анимации на нем.Метод, который выполняет анимацию, выглядит следующим образом:
- (void) animateView:(UIView*) aView toPosition:(CGPoint) aPositionEnd duration:(CGFloat)duration delegate:(id)delegate {
[self.layer addSublayer:aView.layer];
CGPoint aViewPosition = aView.center;
aView.center = OUT_OF_BOUNDS_POSITION; // Make sure this image position is somewhere out of the view
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, aViewPosition.x, aViewPosition.y);
CGPathAddQuadCurveToPoint(path, NULL, aPositionEnd.x, aViewPosition.y, aPositionEnd.x, aPositionEnd.y);
// Uncomment this to draw the path the thumbnail will fallow
// [_mainView setPath:path];
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.path = path;
//pathAnimation.duration = duration;
pathAnimation.removedOnCompletion = NO;
CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
CATransform3D t = CATransform3DMakeScale(0.1, 0.1, 1.0);
scaleAnimation.toValue = [NSValue valueWithCATransform3D:t];
scaleAnimation.removedOnCompletion = NO;
CABasicAnimation *alphaAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
alphaAnimation.toValue = [NSNumber numberWithFloat:0.0f];
alphaAnimation.removedOnCompletion = NO;
//CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@""];
//CATransform3D t = CATransform3DMakeRotation(degreesToRadian(60.0f) , 1, 0, 0);
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
animationGroup.animations = [NSArray arrayWithObjects:pathAnimation, scaleAnimation, alphaAnimation, nil];
animationGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animationGroup.duration = duration;
animationGroup.delegate = delegate;
animationGroup.removedOnCompletion = YES;
[aView.layer addAnimation:animationGroup forKey:nil];
CFRelease(path);
}
«aView» - это UIImageView, «self» - это UIViewController, а «делегат» - это NSObject.Если анимация завершается, и я открываю UIViewController, все в порядке: animationDidStop: закончен: вызывается в NSObject, и UIViewController освобождает NSObject в его dealloc.Однако, если я открываю UIViewController во время анимации, animationDidStop: закончен: вызывается, как и раньше, но впоследствии NSObject не освобождается, даже если animationGroup.removedOnCompletion установлено в YES!Это определенно происходит, потому что CAAnimationGroup не освобождает делегата, как и должно быть.(Делегаты CAAnimation сохраняются.) Я понятия не имею, почему это будет.Любые идеи / предложения?
Возможно, это как-то связано с поведением, которое я спросил о здесь .UINavigationControllers просто глючат?