标签:style blog class code java tar
声明:转载请注明http://www.cnblogs.com/letougaozao/p/3708887.html
整体效果展示
一、新建关卡控制器
#pragma mark -加载图片 - (void)loadViews { [self addView:@"select_easy_bg.jpg" index:0]; [self addView:@"select_normal_bg.jpg" index:1]; [self addView:@"select_hard_bg.jpg" index:2]; [self addView:@"select_insane_bg.jpg" index:3]; } #pragma mark加载图片 - (void)addView:(NSString*)viewName index:(int)index { CGSize size = self.frame.size; BgView *bg = [[BgView alloc]initWithFrame:CGRectMake(size.width * index, 0, size.width, size.height)]; [bg setFullView:viewName]; [self addSubview:bg]; [self sendSubviewToBack:bg]; }
#pragma mark - 加载关卡 - (void)loadStages { //1.从plist文件中加载所有的关卡 NSURL *url = [[NSBundle mainBundle]URLForResource:@"stages" withExtension:@"plist"]; NSArray *stages = [NSArray arrayWithContentsOfURL:url]; int count = stages.count; //2.将关卡中的字典取出,并且转换成一个模型 for (int i = 0; i < count; i++) { NSDictionary *stageDic = stages[i]; //2.1加载关卡的状态 StageRecordModel *stageRecordModel =[[StageRecordTool sharedStageRecordTool] stageRecordWithNo:i + 1]; //2.2加载关卡的信息 StageInfo *stageInfo = [StageInfo stageInfoWith:stageDic]; stageInfo.stageRecordModel = stageRecordModel; stageInfo.stageNo = i + 1; //2.3加载要显示的关卡的View Stage *stageView = [[NSBundle mainBundle]loadNibNamed:@"Stage" owner:nil options:nil][0]; stageView.stageInfo = stageInfo; stageView.tag = i + 1; //2.4为stageView添加手势监听 [stageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(itemClick:)]]; //2.5计算每一个View所在的位置 CGRect stageFrame = stageView.frame; CGFloat stageWidth = self.frame.size.width; CGFloat x = (stageWidth * 4 - stageFrame.size.width * 8)/8; stageFrame.origin.x = (stageFrame.size.width + x) * (i/3) + 27; stageFrame.origin.y = 120 + (i%3)*(stageFrame.size.width + 7); stageView.frame = stageFrame; [self addSubview:stageView]; [self sendSubviewToBack:stageView]; } }
//3.设置scrollView的一些属性 self.contentSize = CGSizeMake(self.frame.size.width * 4, self.frame.size.height); self.pagingEnabled = YES; self.showsHorizontalScrollIndicator = NO;
#pragma mark - 给pageView显示当前的页码 - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { _pageView.currentPage = scrollView.contentOffset.x / scrollView.bounds.size.width; }
#import <Foundation/Foundation.h> #import "StageRecordModel.h" @interface StageInfo : NSObject @property (nonatomic, copy) NSString *icon; @property (nonatomic, copy) NSString *title; @property (nonatomic, copy) NSString *intro; @property (nonatomic, copy) NSString *format; @property (nonatomic, copy) NSString *unit; @property (nonatomic, assign) int stageNo; @property (nonatomic, assign) double max; @property (nonatomic, assign) double min; //让关卡信息拥有一个StageRecordModel属性 @property (nonatomic, strong) StageRecordModel *stageRecordModel; + (StageInfo *)stageInfoWith:(NSDictionary*)dict; @end
#import "StageInfo.h" #define kIcon @"icon" #define kTitle @"title" #define kIntro @"intro" #define kMax @"max" #define kMin @"min" #define kFormat @"format" #define kUnit @"unit" @implementation StageInfo + (StageInfo *)stageInfoWith:(NSDictionary *)dict { StageInfo *stageInfo = [[self alloc]init]; stageInfo.icon = dict[kIcon]; stageInfo.title = dict[kTitle]; stageInfo.intro = dict[kIntro]; stageInfo.format = dict[kFormat]; stageInfo.unit = dict[kUnit]; stageInfo.max = [dict[kMax] doubleValue]; stageInfo.min = [dict[kMin] doubleValue]; return stageInfo; } @end
#import <UIKit/UIKit.h> @class StageInfo; @interface Stage : UIView @property (nonatomic, strong) StageInfo *stageInfo; //关卡数 @property (weak, nonatomic) IBOutlet UIButton *stageNo; //关卡图标 @property (weak, nonatomic) IBOutlet UIImageView *stageIcon; //关卡锁 @property (weak, nonatomic) IBOutlet UIView *stageLock; //关卡覆盖涂层 @property (weak, nonatomic) IBOutlet UIView *stageCover; //关卡边框 @property (weak, nonatomic) IBOutlet UIImageView *stageRim; //新关卡 @property (weak, nonatomic) IBOutlet UIImageView *stageNew; //关卡等级下面的阴影 @property (weak, nonatomic) IBOutlet UIImageView *stageShadow; //关卡的等级 @property (weak, nonatomic) IBOutlet UIImageView *stageRank; @end
@implementation Stage + (id)stageViewWithStageModel:(StageInfo *)stageInfo { Stage *view = [[NSBundle mainBundle] loadNibNamed:@"StageView" owner:nil options:nil][0]; view.stageInfo = stageInfo; return view; } #pragma mark 设置关卡信息 - (void)setStageInfo:(StageInfo *)stageInfo { _stageInfo = stageInfo; // 1.设置编号 [_stageNo setTitle:[NSString stringWithFormat:@"%d", stageInfo.no] forState:UIControlStateNormal]; // 2.设置图标 _stageImage.image = [UIImage imageNamed:stageInfo.icon]; } @end
应用程序开发之模仿史上最牛游戏(二),布布扣,bubuko.com
标签:style blog class code java tar
原文地址:http://www.cnblogs.com/letougaozao/p/3719648.html