超精準(zhǔn)的iOS計(jì)步器實(shí)現(xiàn)代碼
更新時(shí)間:2016年11月22日 15:58:55 作者:十年一品遇如顏
這篇文章主要為大家詳細(xì)介紹了超精準(zhǔn)的iOS計(jì)步器實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了iOS計(jì)步器實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下
#import "ViewController.h"
#import <CoreMotion/CoreMotion.h>
@interface ViewController ()
@property (nonatomic, strong) CMStepCounter *conter;
@property (weak, nonatomic) IBOutlet UILabel *stepLabel;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 1、判斷計(jì)步器是否可用
if (![CMStepCounter isStepCountingAvailable]) {return;}
// 2、開(kāi)始計(jì)步
[self.conter startStepCountingUpdatesToQueue:[NSOperationQueue mainQueue] updateOn:5 withHandler:^(NSInteger numberOfSteps, NSDate * _Nonnull timestamp, NSError * _Nullable error) {
self.stepLabel.text = [NSString stringWithFormat:@"一共走了%ld步", numberOfSteps];
}];
}
- (CMStepCounter *)conter{
if (_conter == nil) {
_conter = [[CMStepCounter alloc] init];
}
return _conter;
}
效果圖:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
iOS基于 UILabel實(shí)現(xiàn)文字添加描邊功能
這篇文章主要介紹了iOS基于 UILabel實(shí)現(xiàn)文字添加描邊功能,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-10-10
iOS tableView實(shí)現(xiàn)頭部拉伸并改變導(dǎo)航條漸變色
這篇文章主要為大家詳細(xì)介紹了iOS tableView實(shí)現(xiàn)頭部拉伸并改變導(dǎo)航條漸變色,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05
詳解適配iOS10 的相關(guān)權(quán)限設(shè)置
在最新版本的iOS10系統(tǒng)中,如果你的項(xiàng)目中訪問(wèn)了隱私數(shù)據(jù),比如:相機(jī)、相冊(cè)、錄音、定位、聯(lián)系人等等。涉及到權(quán)限問(wèn)題,本篇文章主要介紹了適配iOS10 的相關(guān)權(quán)限設(shè)置,有興趣的可以了解一下。2016-12-12
iOS關(guān)鍵字static extern const使用示例詳解
這篇文章主要為大家介紹了iOS關(guān)鍵字static extern const使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11
iOS Xcode8更新后輸出log日志關(guān)閉的方法
今天剛把xcode更新到了xcode8,運(yùn)行發(fā)現(xiàn)好多l(xiāng)og輸出,怎么關(guān)閉呢,不是很清楚,通過(guò)查閱相關(guān)資料順利關(guān)掉這些log日志,下面小編把方法共享下,需要的朋友參考下2016-09-09

