前言:前段时间请假去参加了一个联通举办的乒乓球比赛,虽然没有拿到第一名,但是我也不是最后一名(偷笑)。在比赛中看到裁判员还是用原始的记录方式-纸质来记录分数(虽然不能全部替代纸质),感觉是不是能用手机(这里用手机代表,不是App,为了方便使用后来我也开发了小程序版来记分,实现基本的记分功能,于是它诞生了-比赛记分牌。废话不多说,先看下App的效果图:
设计目的:
用于乒乓球,羽毛球等比赛记分,并可查看比赛记录
功能设计:
小回合记分
大比分记分
随时查看比赛记录
计时功能
一局比赛结束换位功能
实现功能:
小回合记分
大比分记分
记分时不息屏
随时查看比赛记录
摇一摇截屏
可选比赛为普通比赛 标准比赛(标准比赛比普通比赛更严格,必须根据比赛规则结束比赛)
细节:
队名输入
随机先手
翻页、分数上下区域点击、按钮都可增减比分
重新开始比赛
摇一摇截屏
记分时不息屏
待开发功能
计时功能
一局比赛结束换位功能
具体功能实现:
1.页面布局:小比分使用UIPageViewController,可以实现翻页效果和自带的点击效果;使用Masonry和frame混合布局
2.数据存储:fmdb使用
主要详细功能实现:
1.分数视图封装:包括上面的小比分,加减和重置按钮,UIPageViewController的使用;
- 1-1.初始化 底部添加一个背景视图 RBScoreView类
CGFloat width = kSCREENW/2 - 2*KWidth(20);
self.pageBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, width)];
[self addSubview:self.pageBgView];
self.pageVC = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationVertical options:nil];
self.pageVC.view.frame = self.pageBgView.bounds;
// 设置当前显示的控制器
[self.pageVC setViewControllers:@[self.dataArray[0]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
self.pageVC.delegate = self;
self.pageVC.dataSource = self;
[self.pageBgView addSubview:self.pageVC.view];
[self.parentVC addChildViewController:self.pageVC];
- 1-2.仿UITableView代理方法 自定义方法 通过索引获取当前的控制器
- (RBPageChildrenVC *)viewControllerAtIndex:(NSUInteger)index {
// Return the data view controller for the given index.
if (([self.dataArray count] == 0) || (index >= [self.dataArray count])) {
return nil;
}
RBPageChildrenVC *chiledVC = self.dataArray[index];
return chiledVC;
}
- 1-3.仿UITableView代理方法 自定义方法 通过当前的控制器获取索引,number是自控制器的一个属性
- (NSUInteger)indexOfViewController:(RBPageChildrenVC *)viewController {
return viewController.number.integerValue;
}
- 1-4.UIPageViewController代理方法
// 向前翻页展示的ViewController
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSInteger index = [self indexOfViewController:(RBPageChildrenVC *)viewController];
if ((index == 0) || (index == NSNotFound)) {
return nil;
}
index--;
self.currentIndex = index;
return [self viewControllerAtIndex:index];
}
// 向后翻页展示的ViewController
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger index = [self indexOfViewController:(RBPageChildrenVC *)viewController];
if (index == NSNotFound) {
return nil;
}
index++;
self.currentIndex = index;
if (index == [self.dataArray count]) {
return nil;
}
return [self viewControllerAtIndex:index];
}
- 1-5.初始化数据源
- (NSMutableArray *)leftArray {
if (_leftArray == nil) {
_leftArray = [NSMutableArray arrayWithCapacity:0];
for (int i = 0; i <= MAX_COUNT; i++) {
RBPageChildrenVC *childrenVC = [[RBPageChildrenVC alloc] init];
childrenVC.isRed = YES;
childrenVC.number = [NSString stringWithFormat:@"%d", i];
[_leftArray addObject:childrenVC];
}
}
return _leftArray;
}
- 1-6.初始化视图
self.leftScoreView = [[RBScoreView alloc] initWithFrame:CGRectMake(0, 0, width, width + KHeight(10+2*44)) parentVC:self dataArray:self.leftArray];
self.leftScoreView.backgroundColor = RBRedColor;
[self.leftBgView addSubview:self.leftScoreView];
// self.leftScoreView.buttonClickAnimated = YES;
[self.leftScoreView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.leftBgView).offset(0);
make.size.mas_equalTo(CGSizeMake(width, width + KHeight(10+2*44)));
make.top.equalTo(self.leftBgView.mas_centerY).offset(0);
}];
到这里首页基本的视图就OK了,其他的都是很简单控件的使用了。
2.比赛记录数据存储:fmdb数据库封装,小比分的存储
- 2-1.SQLite数据库 基本数据类型
数据类型 | 说明 |
---|---|
NULL | 空值 |
INTEGER | 有符号整数,存储在1、2、3、4、6或8个字节中 |
REAL | 浮点数,存储为8字节的IEEE浮点数 |
TEXT | 文本串,使用数据库编码(UTF-8, UTF-16BE或UTF-16LE)存储 |
BLOB | 大块数据,image存储 |
- 2-2.创建表 注意关闭使用FMDatabase后 记得关闭
NSString *path = [NSHomeDirectory() stringByAppendingString:@"/Documents/Score.db"];
NSLog(@"------path:%@", path);
fmDatabase = [FMDatabase databaseWithPath:path];
BOOL isOpen = [fmDatabase open];
if (isOpen) {
NSLog(@"数据库打开成功!");
} else {
NSLog(@"数据库打开失败!");
}
NSString *sql = @"create table if not exists MyScore(id integer primary key autoincrement, date text, content text, redname text, bluename text, redscore integer, bluescore integer, gametype integer)";
if ([fmDatabase executeUpdate:sql]) {
NSLog(@"表创建成功!");
[fmDatabase close];
} else {
NSLog(@"表创建失败!");
}
- 2-3.插入数据 int或NSInteger类型插入时加@(int/NSInteger),注意插入的是对象
if ([fmDatabase executeUpdate:sql, score.date, score.content, score.redName, score.blueName, @(score.redScore), @(score.blueScore), @(score.blueScore), @(score.gameType)]) {
NSLog(@"数据插入成功!");
[fmDatabase close];
} else {
NSLog(@"数据插入失败!");
NSLog(@"error = %@", [fmDatabase lastErrorMessage]);
}
- 2-4 查询比赛结果
BOOL isOpen = [fmDatabase open];
if (isOpen) {
NSLog(@"数据库打开成功!");
} else {
NSLog(@"数据库打开失败!");
}
NSString *sql = @"select * from MyScore";
FMResultSet *set = [fmDatabase executeQuery:sql];
NSMutableArray *array = [[NSMutableArray alloc] init];
while ([set next]) {
RBScoreModel *scoreModel = [[RBScoreModel alloc] init];
scoreModel.date = [set stringForColumn:@"date"];
scoreModel.content = [set stringForColumn:@"content"];
scoreModel.scoreId = [set intForColumn:@"id"];
scoreModel.redName = [set stringForColumn:@"redname"];
scoreModel.redScore = [set intForColumn:@"redscore"];
scoreModel.blueName = [set stringForColumn:@"bluename"];
scoreModel.blueScore = [set intForColumn:@"bluescore"];
scoreModel.gameType = [set intForColumn:@"gametype"];
[array addObject:scoreModel];
}
[fmDatabase close];
return array;
- 2-5.删除表 删除成功后重新创建table 防止新增字段
- (BOOL)deleteTable {
NSString *path = [NSHomeDirectory() stringByAppendingString:@"/Documents/Score.db"];
NSFileManager *manager = [NSFileManager defaultManager];
NSError *error = nil;
if ([manager fileExistsAtPath:path]) {
BOOL isRemove = [manager removeItemAtPath:path error:&error];
if (isRemove) {
// 删除成功后重新创建table 防止测试时新增字段
[self createTable];
return YES;
}
else {
NSLog(@"%@", error);
return NO;
}
}
else {
return YES;
}
}
2-6.按钮操作添加数据
- 2-6-1.回合结束按钮 构造数据
NSDictionary *littleScoreDic = @{@"redScore":@(self.leftScoreView.currentIndex), @"blueScore":@(self.rightScoreView.currentIndex), @"roundEndTime":[RBTool getCurrentDateWithFormat:@"yyyy-MM-dd HH:mm:ss"]};
[self.littleArray addObject:littleScoreDic];
- 2-6-2.比赛结束按钮 添加数据
RBScoreModel *model = [[RBScoreModel alloc] init];
model.date = [RBTool getCurrentDateWithFormat:@"yyyy-MM-dd HH:mm:ss"];
model.redName = self.leftTeamView.nameText;
model.redScore = self.leftBigScoreTF.text.length == 0?0:self.leftBigScoreTF.text.integerValue;
model.blueName = self.rightTeamView.nameText;
model.blueScore = self.rightBigScoreTF.text.length == 0?0:self.rightBigScoreTF.text.integerValue;
model.gameType = self.gameType;
NSString *content = [RBTool convertObjectToJson:self.littleArray];
model.content = content;
[[FMDBManager sharedDBManager] addScoreModel:model];
至此,文章就该结束了,但是我发现很多人不太会使用比赛记分牌,所以文章末尾添加了比赛记分牌的使用方法。
使用方法:
以乒乓球比赛为例:
1.使用顺序,选择比赛类型,输入比赛双方的队名,摇先手,看谁先发球,然后赢得一方加分数,本回合结束点击按钮回合结束,比赛结束点击比赛结束。
2.“+”按钮用于增加分数,“-”按钮减少分数,“重置”按钮用于重置分数。
3.小比分是大框的比分,代表一个回合的比分;大比分是小框的比分,代表一局比赛的比分。“回合结束”表示一回合(一局)比赛结束,小比分清空,小比分多的一队大比分加1;“比赛结束”表示本局比赛结束,比赛比分全部重置。
4.比赛结束后默认跳转到比赛结果列表,可查看比赛结果。
2019.2.7更新
过年的时候,几经波折终于成功上架AppStore了。
2019.3.19更新
This letter serves as notice of termination of the Apple Developer Program License Agreement (the “ADP Agreement”) and the Apple Developer Agreement (the “Developer Agreement”) between you and Apple effective immediately.
Pursuant to Section 3.2(f) of the ADP Agreement, you agreed that you would not “commit any act intended to interfere with the Apple Software or Services, the intent of this Agreement, or Apple’s business practices including, but not limited to, taking actions that may hinder the performance or intended use of the App Store, B2B Program, or the Program.” Apple has good reason to believe that you violated this Section due to documented indications of fraudulent conduct associated with your account.
Apple is exercising its right to terminate your status as an Apple developer pursuant to the Apple Developer Agreement and is terminating you under the ADP Agreement for dishonest and fraudulent acts relating to that agreement. We would like to remind you of your obligations with regard to all software and other confidential information that you obtained from Apple as an Apple developer and under the ADP Agreement. You must promptly cease all use of and destroy such materials and comply with all the other termination obligations set forth in Section 11.3 of the ADP Agreement and Section 10 of the Apple Developer Agreement.
This letter is not intended to be a complete statement of the facts regarding this matter, and nothing in this letter should be construed as a waiver of any rights or remedies Apple may have, all of which are hereby reserved. Finally, please note that we will deny your reapplication to the Apple Developer Program for at least a year considering the nature of your acts.
没多久开发者账号就被封了,申诉无果,只是说违反了苹果的规则!哎,放弃吧!