我想在用户正确猜测之后制作五彩纸屑效果,我搜索网页并发现看起来非常好的东西,但它只有.m文件,我不知道如何处理头文件。
This is the link to the page with the Confetti effect link
这是.m文件本身,我在这些行上收到错误:
if ((self = [super initWithFrame:frame])) {
self.userInteractionEnabled = NO;
self.backgroundColor = [UIColor clearColor];
_confettiEmitter = (CAEmitterLayer*)self.layer;
为什么会出现错误?
//
// Created by tdimson on 8/15/12.
#import <QuartzCore/QuartzCore.h>
#import "SFSConfettiScreen.h"
@implementation SFSConfettiScreen {
__weak CAEmitterLayer *_confettiEmitter;
CGFloat _decayAmount;
}
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
self.userInteractionEnabled = NO;
self.backgroundColor = [UIColor clearColor];
_confettiEmitter = (CAEmitterLayer*)self.layer;
_confettiEmitter.emitterPosition = CGPointMake(self.bounds.size.width /2, 0);
_confettiEmitter.emitterSize = self.bounds.size;
_confettiEmitter.emitterShape = kCAEmitterLayerLine;
CAEmitterCell *confetti = [CAEmitterCell emitterCell];
confetti.contents = (__bridge id)[[UIImage imageNamed:@"Confetti.png"] CGImage];
confetti.name = @"confetti";
confetti.birthRate = 150;
confetti.lifetime = 5.0;
confetti.color = [[UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:1.0] CGColor];
confetti.redRange = 0.8;
confetti.blueRange = 0.8;
confetti.greenRange = 0.8;
confetti.velocity = 250;
confetti.velocityRange = 50;
confetti.emissionRange = (CGFloat) M_PI_2;
confetti.emissionLongitude = (CGFloat) M_PI;
confetti.yAcceleration = 150;
confetti.scale = 1.0;
confetti.scaleRange = 0.2;
confetti.spinRange = 10.0;
_confettiEmitter.emitterCells = [NSArray arrayWithObject:confetti];
}
return self;
}
+ (Class) layerClass {
return [CAEmitterLayer class];
}
static NSTimeInterval const kDecayStepInterval = 0.1;
- (void) decayStep {
_confettiEmitter.birthRate -=_decayAmount;
if (_confettiEmitter.birthRate < 0) {
_confettiEmitter.birthRate = 0;
} else {
[self performSelector:@selector(decayStep) withObject:nil afterDelay:kDecayStepInterval];
}
}
- (void) decayOverTime:(NSTimeInterval)interval {
_decayAmount = (CGFloat) (_confettiEmitter.birthRate / (interval / kDecayStepInterval));
[self decayStep];
}
- (void) stopEmitting {
_confettiEmitter.birthRate = 0.0;
}
@end
答案 0 :(得分:1)
对此进行逆向工程应该非常简单。它显然是一个UIView
子类,所以这样的东西就足够了,在现代的Objective-C中,你甚至不需要在实现文件中声明实例变量。
@interface SFSConfettiScreen : UIView
@property(nonatomic, weak) CAEmitterLayer *confettiEmitter;
@property(nonatomic, assign) CGFloat decayAmount;
@end
如果你的Xcode版本是4.4或更新版本应该是这样的话。否则,保持实现不变并删除@property
声明,留下空接口声明。这应该也有效;我只是喜欢ivars的属性。