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) {
}];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
自己想到问题出在哪里了
我最近写图表的时候也发现了这个问题,你的这个问题解决了吗?是怎么解决的?
最后要重新覆盖layer的属性保存一下