gpt4 book ai didi

ios - CAEmitterLayer-kCAEmitterLayerCircle,圆形路径?

转载 作者:行者123 更新时间:2023-12-01 17:20:30 24 4
gpt4 key购买 nike

我正在尝试重新创建此效果(请参见下图),但是具有圆形路径,因为我有一个圆形按钮。

这是来源。

https://github.com/uiue/ParticleButton/blob/master/ParticleButton/EmitterView.m

我所做的修改似乎会影响粒子动画的方法,而不是路径。

我尚未深入研究所采用的技术,但是我不相信这有可能吗?

    fireEmitter = (CAEmitterLayer *)self.layer;
//fireEmitter.renderMode = kCAEmitterLayerAdditive;
//fireEmitter.emitterShape = kCAEmitterLayerLine;

// CGPoint pt = [[touches anyObject] locationInView:self];
float multiplier = 0.25f;
fireEmitter.emitterPosition = self.center;
fireEmitter.emitterMode = kCAEmitterLayerOutline;
fireEmitter.emitterShape = kCAEmitterLayerCircle;
fireEmitter.renderMode = kCAEmitterLayerAdditive;
fireEmitter.emitterSize = CGSizeMake(100 * multiplier, 0);

最佳答案

您只是在此处设置发射器属性(与其位置动画无关)。您的问题中缺少创建动画并将其添加到按钮的部分(但存在于示例项目中)。

drawRect:方法中,动画添加如下:

-(void)drawRect:(CGRect)rect
{
CGMutablePathRef path = CGPathCreateMutable();

CGPathAddRect(path, NULL, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height));

CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.duration = 3;
animation.timingFunction = [CAMediaTimingFunction functionWithName:@"easeInEaseOut"];
animation.repeatCount = MAXFLOAT;
animation.path = path; // That's what defines the path of the animation
[emitterView.layer addAnimation:animation forKey:@"test"];
}

实质上就是说,采用该路径(现在是一个具有按钮尺寸的矩形),并沿该路径设置 emitterView s(粒子)位置的动画3秒钟(并永久重复)。

因此,简单地将 animation.path更改为类似这样的内容,可以定义发射器遵循的循环路径:
animation.path = [UIBezierPath bezierPathWithOvalInRect:rect].CGPath;
(基本上是椭圆形,具有按钮的尺寸-可能是您想要的,或者不是您想要的-但您知道了...)

注意:我并不是说 drawRect:是创建和添加动画的最佳位置(它只是基于您提供的示例)。如果您具有与按钮的圆形形状匹配的路径,则可以按照自己喜欢的任何方式创建和添加动画。

关于ios - CAEmitterLayer-kCAEmitterLayerCircle,圆形路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24157766/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com