簡體   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