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

发布于 2022-09-02 11:42:06 字数 4410 浏览 22 评论 0

clipboard.png

上图是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"];
    

}

clipboard.png

第二张图是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) {
        
    }];
    
    
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柠檬 2022-09-09 11:42:07

自己想到问题出在哪里了

一念一轮回 2022-09-09 11:42:07

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

空名 2022-09-09 11:42:07

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文