Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UIViewController弹出->;CAAnimation.delegate是否未发布?_Objective C_Ios_Cocoa Touch - Fatal编程技术网

Objective c UIViewController弹出->;CAAnimation.delegate是否未发布?

Objective c UIViewController弹出->;CAAnimation.delegate是否未发布?,objective-c,ios,cocoa-touch,Objective C,Ios,Cocoa Touch,我在UINavigationController上有一个UIViewController,它有一个特殊的NSObject,可以在上面执行一些动画。执行动画的方法如下所示: - (void) animateView:(UIView*) aView toPosition:(CGPoint) aPositionEnd duration:(CGFloat)duration delegate:(id)delegate { [self.layer addSublayer:aView.layer]; CGP

我在UINavigationController上有一个UIViewController,它有一个特殊的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,“delegate”是NSObject。如果动画完成,我弹出UIViewController,一切正常:animationDidStop:finished:在NSObject中调用,UIViewController在其dealoc中释放NSObject。但是,如果在动画发生时我弹出UIViewController,则会像以前一样调用animationDidStop:finished:,但之后不会释放NSObject,即使animationGroup.removedOnCompletion设置为YES!这种情况肯定会发生,因为CAAnimationGroup并没有像应该的那样释放委托。(保留了民航代表)我不知道为什么会这样。有什么想法/建议吗


也许这在某种程度上与我所问的行为有关。UINavigationControllers只是有问题吗?

我觉得这更像是您对以下两种方法的期望

animationDidStop:finished:

例如,当弹出视图控制器且动画仍在运行时,bool值是否传递给委托方法NO?在这种情况下,您不能期望它在完成时被删除,因为您从未给过它完成的机会

在这种情况下,您需要使用手动删除动画

removeAllAnimations

在动画仍在运行时弹出视图控制器。

我切换到addSubview:而不是addSublayer:并且一切正常。

为什么不在animationDidStop:中将代理设置为零?如果可以的话!我有个例外,抱怨CAAnimationGroup是只读的或类似的。嗯,这是个好主意。我一定要试试。似乎是一个奇怪的设计决定,如果是真的,但…不幸的是,这并没有起作用。动画到达回调时没有动画关键点。我发现委托完成后从未被释放:否。这可能是CAAnimationGroup的一个bug。同时,我可能需要在回调中手动调用[self release]。
removeAllAnimations