gpt4 book ai didi

iphone - 与 CAEmitterLayer 一起使用的代码的问题

转载 作者:行者123 更新时间:2023-11-29 13:23:54 25 4
gpt4 key购买 nike

我想在用户猜对后制作五彩纸屑效果,我在网上搜索了一些看起来不错的东西,但是它只有.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

最佳答案

逆向工程应该非常简单。它显然是一个 UIView 子类,所以这样的东西应该足够了,在现代的 Objective-C 中,您甚至不需要在实现文件中声明实例变量。

@interface SFSConfettiScreen : UIView

@property(nonatomic, weak) CAEmitterLayer *confettiEmitter;
@property(nonatomic, assign) CGFloat decayAmount;

@end

如果您的 Xcode 版本是 4.4 或更高版本,这应该可以工作,因为它应该是。否则,按原样保留实现并删除 @property 声明,留下一个空的接口(interface)声明。那也应该有效;与 ivars 相比,我更喜欢属性。

关于iphone - 与 CAEmitterLayer 一起使用的代码的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13663804/

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