国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

分享iOS上的秒表小應用

2020-02-19 15:52:08
字體:
來源:轉載
供稿:網友

在iOS開發中多線程是不可避免的,實際上多線程是為單核CPU設計的,CPU只能執行一個線程,下文是武林技術頻道小編和大家分享iOS上的秒表小應用的介紹。

模仿實現一下ios系統應用時鐘里的秒表程序,就是這個應用:

2015102994851336.png (324×486)

主要實現的功能:
1.由start/stop鍵實現計時
2.有reset/lap鍵實現復位和計次

需要思考的點:
1.時間的表示方法(有很多種思路)
2.計次數據的倒序排列,即計次1的數據在最底端,依次向上為計次2,計次3的時間數據

我的實現:
ARC省去了我們自行管理內存的大部分事情,寫慣了c++于是舒服了很多

?

復制代碼 代碼如下:

- (IBAction) startOrstop:(UIButton *)sender?
{?
??? //點擊切換按鈕背景圖?
??? UIImage *newImage = (checked) ? [UIImage imageNamed:@"red.png"] : [UIImage imageNamed:@"green.png"];?
??? [leftBtn setBackgroundImage:newImage forState:UIControlStateNormal];?
?????
??? NSString *titlel = (checked) ? (@"Stop") : (@"Start");?
??? [leftBtn setTitle:titlel forState:UIControlStateNormal];?
??? NSString *titler = (checked) ? (@"Lap") : (@"Reset");?
??? [rightBtn setTitle:titler forState:UIControlStateNormal];?
???
???????
??? if (checked)?? //start?
??? {?
??????? timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateTime) userInfo:nil repeats:YES];?
??? }else {??????? //stop?
??????? [timer invalidate];?
??? }?
?????
??? checked = !checked;?
}?
?
- (IBAction) resetOrLap:(UIButton *)sender?
{?
??? static NSInteger count = 1;?
?????
??? if (checked) //reset?
??? {?
??????? time = time_lap = 0.0;?
??????? timestr = [NSString stringWithFormat:@"00:00.0"];?
??????? [label setText:timestr];?
??????? list_time = list_lap = nil;?
??????? count = 1;?
??????? [tableview reloadData];?
?????????
??? }else {????? //lap?
??????? if (list_time == nil) {?
??????????? list_time = [[NSArray alloc]initWithObjects:timestr_lap, nil];?
??????????? list_lap = [[NSArray alloc]initWithObjects:[NSString stringWithFormat:@"%d",count++], nil];?
??????? }else {?
#if 0?
??????????? [list arrayByAddingObject:timestr];?
#else?
??????????? NSArray *array = [[NSArray alloc]initWithObjects:timestr_lap, nil];?
??????????? list_time = [array arrayByAddingObjectsFromArray:list_time];?
??????????? array = [[NSArray alloc]initWithObjects:[NSString stringWithFormat:@"%d",count++], nil];?
??????????? list_lap = [array arrayByAddingObjectsFromArray:list_lap];?
#endif?
??????? }?
??????? time_lap = 0;?
??????? [tableview reloadData];?
???? }?
}?
?
- (float) updateTime?
{?
??? time+=0.1;?
??? time_lap +=0.1;?
??? timestr = [NSString stringWithFormat:@"%02d:%04.1f",(int)(time / 60) ,time - ( 60 * (int)( time / 60 ) )];?
??? timestr_lap = [NSString stringWithFormat:@"%02d:%04.1f",(int)(time_lap / 60) ,time_lap - ( 60 * (int)( time_lap / 60 ) )];?
??? [label setText:timestr];?
??? return time;?
}?
?
?
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section?
{?
??? return [list_time count];?
}?
?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath?
{?
??? static NSString *tableViewIdentifier = @"tableViewIdentifier";?
??? UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableViewIdentifier];?
??? if (cell == nil) {?
??????? cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:tableViewIdentifier];??
??? }?
?????
??? NSUInteger row = [indexPath row];?
?????
??? cell.detailTextLabel.text = [list_time objectAtIndex:row];?
??? cell.detailTextLabel.textColor = [UIColor blackColor];?
??? cell.detailTextLabel.font = [UIFont boldSystemFontOfSize:25.0];?
??? cell.detailTextLabel.textAlignment = UITextAlignmentCenter;?
?????
??? NSString *text = [[NSString alloc]initWithFormat:@"lap %@", [list_lap objectAtIndex:row]];?
??? cell.textLabel.text = text;?
??? return cell;?
}?

?

?

?

?

?

2015102994921137.png (320×480)

2015102994939154.png (320×480)

待改進的地方:
1.對于時間的計時操作和UI事件應該分不同線程實現,這里我偷懶了
2.對于時間的表示方法其實也是很偷懶的,沒有按照標準的秒分進位表示

通過武林技術頻道小編分享iOS上的秒表小應用,相信大家都有了一定的了解,想要了解更多的技術內容,請繼續關注武林技術頻道吧!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宜章县| 怀远县| 清河县| 德安县| 秦皇岛市| 泰来县| 肥城市| 延边| 克拉玛依市| 沙湾县| 科尔| 曲靖市| 丹巴县| 四会市| 崇明县| 合作市| 汕尾市| 石柱| 长治县| 和平县| 晴隆县| 铜鼓县| 鹤庆县| 邮箱| 上高县| 石狮市| 绥宁县| 灌阳县| 南昌市| 崇礼县| 馆陶县| 镇远县| 徐州市| 新密市| 育儿| 温州市| 醴陵市| 郓城县| 浮梁县| 交口县| 故城县|