IOS 출석 필터(흩 어 짐 효과)의 인 스 턴 스 코드 구현
난화 효과
#import <Foundation/Foundation.h>
///
@interface RewardSuccess : NSObject
/**
*
*/
+ (void)show;
@end
#import "RewardSuccess.h"
#import "RewardSuccessWindow.h"
#define EmitterColor_Red [UIColor colorWithRed:255/255.0 green:0 blue:139/255.0 alpha:1]
#define EmitterColor_Yellow [UIColor colorWithRed:251/255.0 green:197/255.0 blue:13/255.0 alpha:1]
#define EmitterColor_Blue [UIColor colorWithRed:50/255.0 green:170/255.0 blue:207/255.0 alpha:1]
@implementation RewardSuccess
+ (void)show
{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UIView *backgroundView = [[UIView alloc] initWithFrame:window.bounds];
backgroundView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.8];
[window addSubview:backgroundView];
RewardSuccessWindow *successWindow = [[RewardSuccessWindow alloc] initWithFrame:CGRectZero];
[backgroundView addSubview:successWindow];
//
successWindow.transform=CGAffineTransformMakeScale(0.01f, 0.01f);
successWindow.alpha = 0;
[UIView animateWithDuration:0.4 animations:^{
successWindow.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
successWindow.alpha = 1;
}];
//3s
double delayInSeconds = 3;
dispatch_time_t delayInNanoSeconds = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(delayInNanoSeconds, dispatch_get_main_queue(), ^(void){
[UIView animateWithDuration:0.4 animations:^{
successWindow.transform = CGAffineTransformMakeScale(.3f, .3f);
successWindow.alpha = 0;
}completion:^(BOOL finished) {
[backgroundView removeFromSuperview];
}];
});
//
CAEmitterLayer *emitterLayer = addEmitterLayer(backgroundView,successWindow);
startAnimate(emitterLayer);
}
CAEmitterLayer *addEmitterLayer(UIView *view,UIView *window)
{
//
CAEmitterCell *subCell1 = subCell(imageWithColor(EmitterColor_Red));
subCell1.name = @"red";
CAEmitterCell *subCell2 = subCell(imageWithColor(EmitterColor_Yellow));
subCell2.name = @"yellow";
CAEmitterCell *subCell3 = subCell(imageWithColor(EmitterColor_Blue));
subCell3.name = @"blue";
CAEmitterCell *subCell4 = subCell([UIImage imageNamed:@"success_star"]);
subCell4.name = @"star";
CAEmitterLayer *emitterLayer = [CAEmitterLayer layer];
emitterLayer.emitterPosition = window.center;
emitterLayer.emitterPosition = window.center;
emitterLayer.emitterSize = window.bounds.size;
emitterLayer.emitterMode = kCAEmitterLayerOutline;
emitterLayer.emitterShape = kCAEmitterLayerRectangle;
emitterLayer.renderMode = kCAEmitterLayerOldestFirst;
emitterLayer.emitterCells = @[subCell1,subCell2,subCell3,subCell4];
[view.layer addSublayer:emitterLayer];
return emitterLayer;
}
void startAnimate(CAEmitterLayer *emitterLayer)
{
CABasicAnimation *redBurst = [CABasicAnimation animationWithKeyPath:@"emitterCells.red.birthRate"];
redBurst.fromValue = [NSNumber numberWithFloat:30];
redBurst.toValue = [NSNumber numberWithFloat: 0.0];
redBurst.duration = 0.5;
redBurst.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
CABasicAnimation *yellowBurst = [CABasicAnimation animationWithKeyPath:@"emitterCells.yellow.birthRate"];
yellowBurst.fromValue = [NSNumber numberWithFloat:30];
yellowBurst.toValue = [NSNumber numberWithFloat: 0.0];
yellowBurst.duration = 0.5;
yellowBurst.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
CABasicAnimation *blueBurst = [CABasicAnimation animationWithKeyPath:@"emitterCells.blue.birthRate"];
blueBurst.fromValue = [NSNumber numberWithFloat:30];
blueBurst.toValue = [NSNumber numberWithFloat: 0.0];
blueBurst.duration = 0.5;
blueBurst.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
CABasicAnimation *starBurst = [CABasicAnimation animationWithKeyPath:@"emitterCells.star.birthRate"];
starBurst.fromValue = [NSNumber numberWithFloat:30];
starBurst.toValue = [NSNumber numberWithFloat: 0.0];
starBurst.duration = 0.5;
starBurst.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = @[redBurst,yellowBurst,blueBurst,starBurst];
[emitterLayer addAnimation:group forKey:@"heartsBurst"];
}
CAEmitterCell *subCell(UIImage *image)
{
CAEmitterCell * cell = [CAEmitterCell emitterCell];
cell.name = @"heart";
cell.contents = (__bridge id _Nullable)image.CGImage;
//
cell.scale = 0.6;
cell.scaleRange = 0.6;
//
// cell.birthRate = 40;
cell.lifetime = 20;
//
// snowCell.alphaSpeed = -0.7;
// snowCell.redSpeed = 0.1;
//
cell.velocity = 200;
cell.velocityRange = 200;
cell.yAcceleration = 9.8;
cell.xAcceleration = 0;
//
cell.emissionRange = M_PI;
cell.scaleSpeed = -0.05;
//// cell.alphaSpeed = -0.3;
cell.spin = 2 * M_PI;
cell.spinRange = 2 * M_PI;
return cell;
}
UIImage *imageWithColor(UIColor *color)
{
CGRect rect = CGRectMake(0, 0, 13, 17);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@end
보상 수령 성공 알림 상자
#import <UIKit/UIKit.h>
///
@interface RewardSuccessWindow : UIView
@end
#import "RewardSuccessWindow.h"
static CGFloat SuccessWindow_width = 270;
static CGFloat SuccessWindow_hight = 170;
@implementation RewardSuccessWindow
(instancetype)initWithFrame:(CGRect)frame
{
CGSize screenSize = [UIScreen mainScreen].bounds.size;
self = [super initWithFrame:CGRectMake((screenSize.width - SuccessWindow_width)/2.0 , (screenSize.height - SuccessWindow_hight)/2.0, SuccessWindow_width, SuccessWindow_hight)];
if (self)
{
[self configSubViews];
}
return self;
}
- (void)configSubViews
{
self.backgroundColor = [UIColor whiteColor];
self.layer.cornerRadius = 10;
self.layer.masksToBounds = YES;
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 45, SuccessWindow_width, 22)];
titleLabel.text = @" , !";
titleLabel.font = [UIFont systemFontOfSize:19.0];
titleLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:titleLabel];
UILabel *expLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 75, SuccessWindow_width, 43)];
expLabel.font = [UIFont systemFontOfSize:15];
expLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:expLabel];
NSString *string = @" :+6";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
[attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, string.length)];
[attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"MarkerFelt-Thin" size:35] range:NSMakeRange(5,2)];
NSShadow *shadow =[[NSShadow alloc] init];
shadow.shadowOffset = CGSizeMake(1, 3);
[attributedString addAttribute:NSShadowAttributeName value:shadow range:NSMakeRange(5,2)];
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(5,2)];
expLabel.attributedText = attributedString;
UILabel *bottomLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 135, SuccessWindow_width, 22)];
bottomLabel.text = @" -> ";
bottomLabel.font = [UIFont systemFontOfSize:13.0];
bottomLabel.textAlignment = NSTextAlignmentCenter;
bottomLabel.textColor = [UIColor colorWithRed:177/255.0 green:177/255.0 blue:177/255.0 alpha:1];
[self addSubview:bottomLabel];
}
@end
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Swift의 패스트 패스Objective-C를 대체하기 위해 만들어졌지만 Xcode는 Objective-C 런타임 라이브러리를 사용하기 때문에 Swift와 함께 C, C++ 및 Objective-C를 컴파일할 수 있습니다. Xcode는 S...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.