我有一個UIViewController UINavigationController與一個特殊的NSObject,它執行一些動畫。執行該動畫的方法是這樣的:UIViewController彈出 - > CAAnimation.delegate沒有發佈?
- (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,「自我」是的UIViewController,和「代理」是NSObject的。如果動畫完成並彈出UIViewController,則一切正常:animationDidStop:finished:在NSObject中調用,並且UIViewController在其dealloc中釋放NSObject。但是,如果在動畫發生時彈出UIViewController,則animationDidStop:finished:將像以前一樣被調用,但即使animationGroup.removedOnCompletion設置爲YES,NSObject也不會解除分配!這肯定發生,因爲CAAnimationGroup沒有發佈委託,因爲它應該是。 (CAAnimation代表保留。)我不知道爲什麼會這樣。任何想法/建議?
也許這在某種程度上與我詢問的有關here的行爲有關。 UINavigationControllers只是越野車?
爲什麼不在animationDidStop中設置委託爲零:? – Eiko
如果只有!我收到一個抱怨CAAnimationGroup爲只讀或類似的異常。 – Archagon