繁体   English   中英

iPhone / xCode-动画代码第4次运行时为EXC_BAD_ACCESS

[英]iPhone/xCode - EXC_BAD_ACCESS on 4th run of Animation Code

该代码在前3次有效,并且每次都成功运行,并在第4次运行时崩溃, Thread 1: EXC_BAD_ACCESS (code=1, address=0x4) 我整个下午都在研究,但什么也没想出来,是否是我没有放东西?

- (void)animateImageView:(UIImageView *)imageViewForAnimation
{
        imageViewForAnimation.alpha = 1.0f;
        CGRect imageFrame = imageViewForAnimation.frame;
        //Your image frame.origin from where the animation need to get start
        CGPoint viewOrigin = imageViewForAnimation.frame.origin;
        viewOrigin.y = viewOrigin.y + imageFrame.size.height / 2.0f;
        viewOrigin.x = viewOrigin.x + imageFrame.size.width / 2.0f;

        imageViewForAnimation.frame = imageFrame;
        imageViewForAnimation.layer.position = viewOrigin;
        [self.view addSubview:imageViewForAnimation];

        // Set up fade out effect
        CABasicAnimation *fadeOutAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
        [fadeOutAnimation setToValue:[NSNumber numberWithFloat:0.3]];
        fadeOutAnimation.fillMode = kCAFillModeForwards;
        fadeOutAnimation.removedOnCompletion = NO;

        // Set up scaling
        CABasicAnimation *resizeAnimation = [CABasicAnimation animationWithKeyPath:@"bounds.size"];
        [resizeAnimation setToValue:[NSValue valueWithCGSize:CGSizeMake(40.0f, imageFrame.size.height * (40.0f / imageFrame.size.width))]];
        resizeAnimation.fillMode = kCAFillModeForwards;
        resizeAnimation.removedOnCompletion = NO;

        // Set up path movement
        CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
        pathAnimation.calculationMode = kCAAnimationPaced;
        pathAnimation.fillMode = kCAFillModeForwards;
        pathAnimation.removedOnCompletion = NO;
        //Setting Endpoint of the animation
        CGPoint endPoint = CGPointMake(250.0f, 10.0f);
        //to end animation in last tab use
        //CGPoint endPoint = CGPointMake( 320-40.0f, 480.0f);
        CGMutablePathRef curvedPath = CGPathCreateMutable();
        CGPathMoveToPoint(curvedPath, NULL, viewOrigin.x, viewOrigin.y);
        CGPathAddCurveToPoint(curvedPath, NULL, endPoint.x, viewOrigin.y, endPoint.x, viewOrigin.y, endPoint.x, endPoint.y);
        pathAnimation.path = curvedPath;
        CGPathRelease(curvedPath);

        CAAnimationGroup *group = [CAAnimationGroup animation];
        group.fillMode = kCAFillModeForwards;
        group.removedOnCompletion = NO;
        [group setAnimations:[NSArray arrayWithObjects:fadeOutAnimation, pathAnimation, resizeAnimation, nil]];
        group.duration = 0.7f;
        group.delegate = self;
        //[group setValue:@"groupAnimation" forKey:@"animationName"];
        [group setValue:imageViewForAnimation forKey:@"imageViewBeingAnimated"];

        [imageViewForAnimation.layer addAnimation:group forKey:@"savingAnimation"];


        [imageViewForAnimation release];

}

删除发行版。 我的建议之所以有效,是因为对象imageViewForAnimation是您方法的参数,并且您的方法中没有任何东西向对象添加保留。 因此,有必要对imageViewForAnimation对象的保留计数进行不必要的递减。 仅在保留后释放。 保持它们在同一范围内。

更好的是,使用ARC ARC,您只需转到Xcode中的菜单栏,依次单击“编辑”>“重构”>“转换为Objective-C ARC ...”,然后仔细进行操作。 它将删除Obj-C内容的保留和释放。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM