如何在CAEmitterCell的入口处制作动画?

时间:2014-10-30 18:22:15

标签: ios cocoa-touch caemitterlayer

目前,我的粒子突然以完整的形状和形式出现在屏幕上。我想要的是细胞要么以0.0不透明度开始,要么动画达到完全不透明度,要么以0.0刻度开始,动画最高为1.0刻度。我无法在网上找到有关如何执行此操作的任何内容。

3 个答案:

答案 0 :(得分:0)

你可以为CAEmitterCell的各种属性设置动画,animating the CAEmitterCell Color property有一个很好的例子可以让你很好地了解你应该做些什么来获得你想要的效果。

CAEmitters上有很多很棒的资源,一个很好的资源是Tutorial: Particle Systems in Core Animation with CAEmitterLayer,另一个是Apple的Fireworks Sample Code

答案 1 :(得分:0)

检查此链接是一个完美的答案:http://invasivecode.tumblr.com/post/4448661320/core-animation-part-iii-basic-animations
如果您想了解更多信息,请尝试以下链接:https://invasivecode.com/weblog/caemitterlayer-and-the-ios-particle-system-lets/
试试这段代码......

    #import "DWFParticleView.h"
#import <QuartzCore/QuartzCore.h>

@implementation DWFParticleView
{
    CAEmitterLayer* fireEmitter; //1
}

-(void)awakeFromNib
{
    //set ref to the layer
    fireEmitter = (CAEmitterLayer*)self.layer; //2
}

+ (Class) layerClass //3
{
    //configure the UIView to have emitter layer
    return [CAEmitterLayer class];
}

@end

答案 2 :(得分:-1)

如果它回答了你的问题,试试这个......

@interface
ViewController ()
@property
(
nonatomic
,
strong
)
CALayer
*colorLayer;
@end
@implementation
ViewController
- (
void
)viewDidLoad
{
[
super
viewDidLoad
];
//create a red layer
self
.colorLayer = [
CALayer
layer
];
self
.colorLayer.
frame
=
CGRectMake
(
0
,
0
,
100
,
100
);
self
.colorLayer.
position
=
CGPointMake
(
self
.
view
.
bounds
.
size
.
width
/
2
,
self
.
view
.
bounds
.
size
.
height
/
2
);
self
.colorLayer.
backgroundColor
= [
UIColor
redColor
].
CGColor
;
[
self
.
view
.
layer
addSublayer
:
se
lf
.colorLayer];
}
- (
void
)touchesBegan:(
NSSet
*)touches withEvent:(
UIEvent
*)event
{
//get the touch point
CGPoint
point = [[touches
anyObject
]
locationInView
:
self
.
view
];
//check if we've tapped the moving layer
if
([
self
.colorLayer.
presentationLayer
hitTest
:point])
{
//randomize the layer background color
CGFloat
red =
arc4random
() / (
CGFloat
)
INT_MAX
;
CGFloat
green =
arc4random
() / (
CGFloat
)
INT_MAX
;
CGFloat
blue =
arc4random
() / (
CGFloat
)
INT_MAX
;
self
.colorLayer.
backgroundColor
= [
UIColor
colorWithRed
:red
green
:green
blue
:blue
alpha
:
1.0
].
CGColor
;
}
else
{
//otherwise (slowly) move the layer to new position
[
CATransaction
beg
in
];
[
CATransaction
setAnimationDuration
:
4.0
];
self
.colorLayer.
position
= point;
ptg11539634
[
CATransaction
commit
];
}
}
@end