标签:des style blog class code java
声明:转载请注明http://www.cnblogs.com/letougaozao/p/3720679.html
- (CAAnimationGroup *)animationCroup { //1.摇摆动画 CAKeyframeAnimation *shake = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"]; CGFloat angle = M_PI_4/4; shake.values = @[@(-angle), @(angle), @(-angle)]; shake.repeatCount = 3; //2.伸缩动画 CAKeyframeAnimation *scale = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"]; scale.values = @[@1.2, @1]; //3.添加动画组 CAAnimationGroup *group = [CAAnimationGroup animation]; group.animations = @[shake, scale]; return group; }
2.执行前面的动画且设置代理(动画执行完之后执行后面的动画)
//0.点击了,覆盖层就消失,且执行动画过程中,不允许用户交互 [self setUserInteractionEnabled:NO]; [_stageCover removeFromSuperview]; //1.播放动画 CAAnimationGroup *group = [self animationCroup]; group.delegate = self; [self.layer addAnimation:group forKey:nil]; //2.播放声音 [[SoundManager sharedSoundManager] playSound:kSoundDrop];
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag { //1.锁掉下来 CGFloat destY = [UIScreen mainScreen].bounds.size.height - self.frame.origin.y; CGFloat duration = destY/1000; [UIView animateWithDuration:duration animations:^{ CGRect frame = _stageLock.frame; frame.origin.y = destY; _stageLock.frame = frame; } completion:^(BOOL finished) { [_stageLock removeFromSuperview]; [_stageNew setHidden:NO]; _stageRim.image = [UIImage imageNamed:@"select_stage_new.png"]; CAAnimationGroup *group = [self animationCroup]; [self.stageNew.layer addAnimation:group forKey:nil]; [self setUserInteractionEnabled:YES]; }]; }
//分数 @property (nonatomic, assign) double score; //编号 @property (nonatomic, assign) int no; //等级(A~F,S) @property (nonatomic, copy) NSString *rank; //状态 @property (nonatomic, assign, getter = isUnlock) BOOL unlock;
#import "StageRecordModel.h" #define kRank @"rank" #define kNo @"no" #define kUnlock @"unlock" #define kScore @"score" @implementation StageRecordModel - (id)initWithCoder:(NSCoder *)aDecoder { if (self = [super init]) { self.rank = [aDecoder decodeObjectForKey:kRank]; self.no = [aDecoder decodeIntForKey:kNo]; self.score = [aDecoder decodeDoubleForKey:kScore]; self.unlock = [aDecoder decodeBoolForKey:kUnlock]; } return self; } - (void)encodeWithCoder:(NSCoder *)aCoder { [aCoder encodeObject:self.rank forKey:kRank]; [aCoder encodeInt:self.no forKey:kNo]; [aCoder encodeDouble:self.score forKey:kScore]; [aCoder encodeBool:self.isUnlock forKey:kUnlock]; } @end
#define kPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:@"records.data"]
//存档 - (void)saveStageRecord:(StageRecordModel *)stageRecordModel { if (stageRecordModel.no < 0) return; [allRecords setObject:stageRecordModel forKey:@(stageRecordModel.no)]; [NSKeyedArchiver archiveRootObject:allRecords toFile:kPath]; }
- (id)init { if (self = [super init]) { allRecords = [NSKeyedUnarchiver unarchiveObjectWithFile:kPath]; if (!allRecords) { allRecords = [NSMutableDictionary dictionary]; StageRecordModel *stageRecordModel = [[StageRecordModel alloc] init]; stageRecordModel.no = 1; [allRecords setObject:stageRecordModel forKey:@(stageRecordModel.no)]; } } return self; }
//读档 - (StageRecordModel *)stageRecordWithNo:(int)no { return allRecords[@(no)]; }
singleton_interface(StageRecordTool)
singeton_implementation(StageRecordTool)
//让关卡信息拥有一个StageRecordModel属性 @property (nonatomic, strong) StageRecordModel *stageRecordModel;
//2.1加载关卡的状态 StageRecordModel *stageRecordModel =[[StageRecordTool sharedStageRecordTool] stageRecordWithNo:i + 1]; //2.2加载关卡的信息 StageInfo *stageInfo = [StageInfo stageInfoWith:stageDic]; stageInfo.stageRecordModel = stageRecordModel; stageInfo.stageNo = i + 1;
//3.根据关卡的状态,获得关卡显示的内容 [self updateStageState];
#pragma mark 根据关卡状态、获得关卡要显示的内容 - (void)updateStageState { if (!_stageInfo.stageRecordModel) { [self setUserInteractionEnabled:NO]; } else { if (!_stageInfo.stageRecordModel.unlock) { [self updateStageWithWillUnlock]; } else { [self updateStageWithUnlock]; } } } #pragma mark 即将解锁时,执行的代码 - (void)updateStageWithWillUnlock { //0.点击了,覆盖层就消失,且执行动画过程中,不允许用户交互 [self setUserInteractionEnabled:NO]; [_stageCover removeFromSuperview]; //1.播放动画 CAAnimationGroup *group = [self animationCroup]; group.delegate = self; [self.layer addAnimation:group forKey:nil]; //2.播放声音 [[SoundManager sharedSoundManager] playSound:kSoundDrop]; //3.设置unlock属性为YES _stageInfo.stageRecordModel.unlock = YES; [[StageRecordTool sharedStageRecordTool] saveStageRecord:_stageInfo.stageRecordModel]; } #pragma mark 已经解锁,执行的代码 - (void)updateStageWithUnlock { //1.遮盖和锁去掉 [_stageCover removeFromSuperview]; [_stageLock removeFromSuperview]; if (_stageInfo.stageRecordModel.rank == nil) { //2.显示new [_stageNew setHidden:NO]; //3.将边框换成黄色 _stageRim.image = [UIImage imageNamed:@"select_stage_new.png"]; } else { //2.显出阴影、等级 [_stageShadow setHidden:NO]; [_stageRank setHidden:NO]; //3.把new移除 [_stageNew removeFromSuperview]; //4.根据等级显示图片 _stageRank.image = [UIImage imageNamed:[NSString stringWithFormat:@"select_stage_%@.png", _stageInfo.stageRecordModel.rank]]; if ([@"s" isEqualToString:_stageInfo.stageRecordModel.rank]) { [_stageRim startAnimating]; } else { [_stageRim setImage:[UIImage imageNamed:@"select_stage_normal.png"]]; } } } #pragma mark - 解锁的动画 - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag { //1.锁掉下来 CGFloat destY = [UIScreen mainScreen].bounds.size.height - self.frame.origin.y; CGFloat duration = destY/1000; [UIView animateWithDuration:duration animations:^{ CGRect frame = _stageLock.frame; frame.origin.y = destY; _stageLock.frame = frame; } completion:^(BOOL finished) { [_stageLock removeFromSuperview]; [_stageNew setHidden:NO]; _stageRim.image = [UIImage imageNamed:@"select_stage_new.png"]; CAAnimationGroup *group = [self animationCroup]; [self.stageNew.layer addAnimation:group forKey:nil]; [self setUserInteractionEnabled:YES]; }]; } - (CAAnimationGroup *)animationCroup { //1.摇摆动画 CAKeyframeAnimation *shake = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"]; CGFloat angle = M_PI_4/4; shake.values = @[@(-angle), @(angle), @(-angle)]; shake.repeatCount = 3; //2.伸缩动画 CAKeyframeAnimation *scale = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"]; scale.values = @[@1.2, @1]; //3.添加动画组 CAAnimationGroup *group = [CAAnimationGroup animation]; group.animations = @[shake, scale]; return group; }
应用程序开发之模仿史上最牛游戏(三),布布扣,bubuko.com
标签:des style blog class code java
原文地址:http://www.cnblogs.com/letougaozao/p/3720679.html