首发于:泰然论坛
我想这个新的 UIKit 粒子系统最酷的是一个单独的 CAEmitterLayer 可以支持多个
CAEmitterCell。这支持你完成一些相当复杂而且很酷的效果。例如当你创建泉水时,你能拥有
一个 cell 发射水滴,另一个 cell 在泉水上发射水蒸汽!
Getting Started
打开 Xcode,并从主菜单中选择 File\New\New Project,选择 iOS\Application\Single View
Application 模版,点击 Next,键入程序名“DrawWithFire”,再键入 DWF 为前缀,选择 iPhone
for Device Family,确认勾选“Use automatic reference counting”(其他选择框别选)。接
着点击 Next,再点击 Create 保存项目。
选择你的项目,再选择 DrawWithFire 的 target。接着打开 Build Phases 选项卡,展开 Link Binary
With Libraies 部分,再点击“+”按钮,双击 QuartzCore.framework,将 Quartz 绘图功能添
加到项目里面。
我们将创建一个自定义 UIView 类来开始项目,这个类将有 CAEmitterLayer 作为它的层。事实上,
完成这些非常简单,通过重写 UIView 类的+(Class)layerClass 方法并返回一个 CAEmitter 类。
相当酷哦!
创建一个新文件,采用 iOS\Cocoa Touch\Objective-C 类模板,类名为 DWFParticleView,继承
于 UIView。
打开 DWFParticleView.m 并替换为如下代码:
#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];
}
评论0