iOS悬浮窗UIBezierPath圆形扩散转场动画

xiaoxiao2021-02-28  78

demo链接https://github.com/MinLee6/circleExtendedAnimation,

self.startFrame:开始的起点位置

self.presentView:随着圆扩展出现的视图view

- (void)circleBigger { self.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height); [self addSubview:self.presentView]; UIBezierPath *maskStartBP = [UIBezierPath bezierPathWithOvalInRect:self.startFrame]; CGFloat radius = [UIScreen mainScreen].bounds.size.height - 100; UIBezierPath *maskFinalBP = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(self.startFrame, -radius, -radius)]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.path = maskFinalBP.CGPath; maskLayer.backgroundColor = (__bridge CGColorRef)([UIColor whiteColor]); self.presentView.layer.mask = maskLayer; CABasicAnimation *maskLayerAnimation = [CABasicAnimation animationWithKeyPath:@"path"]; maskLayerAnimation.fromValue = (__bridge id)(maskStartBP.CGPath); maskLayerAnimation.toValue = (__bridge id)((maskFinalBP.CGPath)); maskLayerAnimation.duration = 10.0f; maskLayerAnimation.delegate = self; [maskLayer addAnimation:maskLayerAnimation forKey:@"path"]; } 可以在代理方法里处理一些事件

/** * 动画开始时 */ - (void)animationDidStart:(CAAnimation *)theAnimation { } /** * 动画结束时 */ - (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag { self.presentView.layer.mask = nil; }

转载请注明原文地址: https://www.6miu.com/read-68010.html

最新回复(0)