首页 > CABaseAnimation所写的动画完成结果在controller即将消失的时候效果会消失

CABaseAnimation所写的动画完成结果在controller即将消失的时候效果会消失

上图是CABaseAnimation动画完成后的效伙图,
主要代码如下:

+ (void)lineChartView:(UIView *)view beginTime:(NSTimeInterval)beginTime{
    CGPathRef beginPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 0, CGRectGetHeight(view.bounds))].CGPath;
    
    CGPathRef endPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, CGRectGetWidth(view.bounds), CGRectGetHeight(view.bounds))].CGPath;
    
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.fillColor = [UIColor whiteColor].CGColor;
    layer.path = beginPath;
    
    view.layer.mask = layer;
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
    animation.duration = 1;
    animation.beginTime = CACurrentMediaTime() + beginTime;
    animation.fromValue = (id)layer.path;
    animation.toValue = (__bridge id)endPath;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;
    [layer addAnimation:animation forKey:@"shapeLayerPath"];
}

+ (void)lineChartView:(UIView *)view specialPoint:(UIView *)sepcialView beginTime:(NSTimeInterval)beginTime{
    [view addSubview:sepcialView];
    sepcialView.transform = CGAffineTransformMakeTranslation(0, -250);
    
    [UIView animateWithDuration:1 delay:beginTime usingSpringWithDamping:0.8 initialSpringVelocity:10 options:UIViewAnimationOptionTransitionFlipFromTop animations:^{
        sepcialView.transform = CGAffineTransformIdentity;

    } completion:^(BOOL finished) {
        
    }];
    
    
}


+ (void)barChartView:(UIView *)barView beginTime:(NSTimeInterval)beginTime{
    
    CGPathRef beginPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, CGRectGetHeight(barView.bounds), CGRectGetWidth(barView.bounds), 0)].CGPath;
    
    CGPathRef endPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, CGRectGetWidth(barView.bounds), CGRectGetHeight(barView.bounds))].CGPath;
    
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.fillColor = [UIColor whiteColor].CGColor;
    layer.path = beginPath;
    
    barView.layer.mask = layer;
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
    animation.duration = 0.25;
    animation.beginTime = CACurrentMediaTime() + beginTime;
    animation.fromValue = (id)layer.path;
    animation.toValue = (__bridge id)endPath;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    //    animation.delegate = delagte;
    [layer addAnimation:animation forKey:@"shapeLayerPath"];
}

+ (void)msgView:(UIView *)msgView beginTime:(NSTimeInterval)beginTime{
//    CAShapeLayer *layer = [CAShapeLayer layer];
//    layer.fillColor = [UIColor whiteColor].CGColor;
////    layer.opacity = 0;
//    msgView.layer.mask = layer;
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    animation.duration = 0.25;
    animation.beginTime = CACurrentMediaTime() + beginTime;
    animation.fromValue = [NSNumber numberWithFloat:0];
    animation.toValue = [NSNumber numberWithFloat:1.0];
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;
    //    animation.delegate = delagte;
    [msgView.layer addAnimation:animation forKey:@"shapeLayerPath"];
    

}

第二张图是controller右划手势controller即将消失时,第一张图动画所画的效果基本上都消失了

我仔细查了一下 在我的右划时 viewWillDisappear什么操作也没做,不知道这是不是CABaseAnimation动画的问题 因为我的这部分代码就没有问题


+ (void)lineChartView:(UIView *)view specialPoint:(UIView *)sepcialView beginTime:(NSTimeInterval)beginTime{
    [view addSubview:sepcialView];
    sepcialView.transform = CGAffineTransformMakeTranslation(0, -250);
    
    [UIView animateWithDuration:1 delay:beginTime usingSpringWithDamping:0.8 initialSpringVelocity:10 options:UIViewAnimationOptionTransitionFlipFromTop animations:^{
        sepcialView.transform = CGAffineTransformIdentity;

    } completion:^(BOOL finished) {
        
    }];
    
    
}


我最近写图表的时候也发现了这个问题,你的这个问题解决了吗?是怎么解决的?


最后要重新覆盖layer的属性保存一下


自己想到问题出在哪里了

【热门文章】
【热门文章】