以iPhone 7,iOS12.1為例:
創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比禹會(huì)網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式禹會(huì)網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋禹會(huì)地區(qū)。費(fèi)用合理售后完善,十余年實(shí)體公司更值得信賴。
需要用到的工具:時(shí)鐘。
一、在桌面找到時(shí)鐘圖標(biāo),并輕點(diǎn)打開(kāi)。
二、在時(shí)鐘導(dǎo)航欄選擇“計(jì)時(shí)器”并輕點(diǎn)打開(kāi)。
三、點(diǎn)擊“啟動(dòng)”,計(jì)時(shí)器開(kāi)始計(jì)時(shí)。
四、當(dāng)需要計(jì)次的時(shí)候點(diǎn)擊“計(jì)次”即可。
五、屏幕上方的時(shí)間就是累計(jì)的時(shí)間。
蘋果秒表懸浮窗設(shè)置方法:
步驟設(shè)置-—通用-—輔助功能-—assistivetouch-—打開(kāi)就能看見(jiàn)一個(gè)白點(diǎn)就是了其實(shí)就是一個(gè)代替home鍵的虛擬按鍵按主屏幕就能退到桌面按兩下主屏幕就能打開(kāi)桌面設(shè)備內(nèi)還有鎖屏旋轉(zhuǎn)靜音等功能。
也可以打開(kāi)手機(jī)頁(yè)面,兩個(gè)手指按住屏幕,之后同時(shí)往中間滑動(dòng)。然后我們?cè)趶棾鰜?lái)的窗口中點(diǎn)擊打開(kāi)“窗口小工具”。然后我們?cè)趶棾鰜?lái)的窗口中點(diǎn)擊選擇喜歡的時(shí)鐘格式,按住拉到桌面即可。
在開(kāi)發(fā)項(xiàng)目的時(shí)候,需要一個(gè)計(jì)時(shí)器來(lái)做讀秒操作。要求在頁(yè)面切換的時(shí)候,重新進(jìn)入頁(yè)面仍然可以繼續(xù)讀秒。但是,當(dāng)頁(yè)面pop出來(lái)的時(shí)候,定時(shí)器會(huì)自動(dòng)銷毀掉,重新進(jìn)入頁(yè)面的時(shí)候已經(jīng)無(wú)法繼續(xù)進(jìn)行讀秒了。
iOS中常用的定時(shí)器有三種,分別是NSTime,CADisplayLink和GCD。其本質(zhì)都是通過(guò)RunLoop來(lái)實(shí)現(xiàn),但GCD通過(guò)其調(diào)度機(jī)制大大提高了性能。GCD定時(shí)器實(shí)際上是使用了dispatch源(dispatch source),dispatch源監(jiān)聽(tīng)系統(tǒng)內(nèi)核對(duì)象并處理。dispatch類似生產(chǎn)者消費(fèi)者模式,通過(guò)監(jiān)聽(tīng)系統(tǒng)內(nèi)核對(duì)象,在生產(chǎn)者生產(chǎn)數(shù)據(jù)后自動(dòng)通知相應(yīng)的dispatch隊(duì)列執(zhí)行,后者充當(dāng)消費(fèi)者。通過(guò)系統(tǒng)級(jí)調(diào)用,更加精準(zhǔn)。
//–––––––––––––––––––––單例.h––––––––––––––––––––––––
#import?
@interface?CaptchaTimerManager :NSObject
@property?(nonatomic,assign)__blockint?timeout;
+ (id)sharedTimerManager;
- (void)countDown;
@end
//–––––––––––––––––––––單例.m––––––––––––––––––––––––
#import"CaptchaTimerManager.h"
@implementation?CaptchaTimerManager
+ (id)sharedTimerManager{
static?CaptchaTimerManager?*manager =nil;
staticdispatch_once_t?onceToken;
dispatch_once(onceToken, ^{
if?(manager ==nil) {
? ? ? ? manager = [[selfalloc]init];
? ? }
});
return?manager;
}
- (void)countDown{
if?(_timeout?0) {
dispatch_queue_t?queue =?dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);
dispatch_source_t?_timer =?dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER,0,?0,queue);
dispatch_source_set_timer(_timer,dispatch_walltime(NULL,0),1.0*NSEC_PER_SEC,0);?//每秒執(zhí)行
dispatch_source_set_event_handler(_timer, ^{
if(_timeout=0){//倒計(jì)時(shí)結(jié)束,關(guān)閉
dispatch_source_cancel(_timer);
? ? ? ? }else{
_timeout--;
? ? ? ? }
? ? });
dispatch_resume(_timer);
}
}
@end
//–––––––––––––––––––––調(diào)用––––––––––––––––––––––––
#import?"CaptchaTimerManager.h"
@property?(weak,nonatomic)?IBOutletUIButton?*getNUmber;
@property?(nonatomic,assign)?int?timeout;
- (IBAction)getNumberButton:(UIButton?*)sender {
_getNUmber.enabled?=NO;
_timeout?=10;?//倒計(jì)時(shí)時(shí)間
[selftimerCountDown];
}
-(void)viewWillAppear:(BOOL)animated{
CaptchaTimerManager?*manager = [CaptchaTimerManagersharedTimerManager];
int?temp = manager.timeout;
if?(temp 0) {
_timeout= temp;//倒計(jì)時(shí)時(shí)間
_getNUmber.enabled?=NO;
? ? [selftimerCountDown];
}else{
_getNUmber.enabled?=YES;
}
}
- (void)viewWillDisappear:(BOOL)animated{
[superviewWillDisappear:animated];
if?(self.timeout?0) {
CaptchaTimerManager?*manager = [CaptchaTimerManagersharedTimerManager];
if?(manager.timeout?==0) {
? ? ? ? manager.timeout?=_timeout;
[manager?countDown];
? ? }
_timeout?=?0;//置為0,釋放controller
}
}
//控制器里的計(jì)時(shí)器
- (void)timerCountDown {
dispatch_queue_t?queue =?dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);
dispatch_source_t?_timer =?dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER,0,?0,queue);
dispatch_source_set_timer(_timer,dispatch_walltime(NULL,0),1.0*NSEC_PER_SEC,0);?//每秒執(zhí)行
dispatch_source_set_event_handler(_timer, ^{
if(_timeout=0){//倒計(jì)時(shí)結(jié)束,關(guān)閉
? ? ? ?dispatch_source_cancel(_timer);
? ? ? ?dispatch_async(dispatch_get_main_queue(), ^{
? ? ? ? ? ?//這里寫倒計(jì)時(shí)結(jié)束button的處理
? ? ? ? });
? ? }else{
? ? ? ?dispatch_async(dispatch_get_main_queue(), ^{
? ? ? ? ? ?//這里寫倒計(jì)時(shí)期間button的處理(重設(shè)button的tiitle、用戶交互等)
if?(_timeout==1) {
self.title?=@"輸入手機(jī)號(hào)";
_getNUmber.enabled?=YES;
}?else?{
self.title?= [NSStringstringWithFormat:@"%d",_timeout];
? ? ? ? ? ? }
? ? ? ? });
_timeout--;
? ? }
});
dispatch_resume(_timer);
}
總結(jié)自下面兩篇文章
iOS的幾種定時(shí)器及區(qū)別 ? ??
iOS 單例計(jì)時(shí)器(頁(yè)面切換仍然計(jì)時(shí))
demo地址? GitHub - littlePerson/SingletonTimer
歡迎指正批評(píng)!
創(chuàng)建一個(gè)計(jì)時(shí)器就行了。
例:
驗(yàn)證60秒
int timeTick;
NSTimer *timer;
timeTick = 61;//60秒倒計(jì)時(shí)
timer=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
_but.enabled = NO;
-(void)timeFireMethod
{
timeTick--;
if(timeTick==0){
[timer invalidate];
_but.enabled = YES;
[_but setTitle:@"獲取驗(yàn)證碼" forState:UIControlStateNormal];
}else
{
NSString *str = [NSString stringWithFormat:@"%d秒",timeTick];
[_but setTitle:str forState:UIControlStateNormal];
}
}
上面代碼就是實(shí)現(xiàn)了一個(gè)倒計(jì)時(shí)60秒的功能。
1.首先打開(kāi)我們的蘋果手機(jī),找到【時(shí)鐘】后點(diǎn)擊打開(kāi)。
2.打開(kāi)后找到屏幕下方的【秒表】的標(biāo)簽頁(yè)。
3.我們要計(jì)時(shí)是可以點(diǎn)擊【啟動(dòng)】,開(kāi)啟秒表功能。
4.秒表開(kāi)始計(jì)時(shí),同時(shí)右邊按鈕變成【停止】,我們計(jì)時(shí)停止可以點(diǎn)擊停止計(jì)時(shí)。右邊的【計(jì)次】數(shù)字會(huì)顯示秒表的次數(shù)。
蘋果在主菜單中找到時(shí)鐘圖標(biāo)這里設(shè)置秒表懸浮功能。
蘋果在主菜單中找到時(shí)鐘圖標(biāo),然后輕觸該圖標(biāo)。您可以在這里設(shè)置世界時(shí)鐘、鬧鐘、倒計(jì)時(shí)和秒表功能。在世界時(shí)鐘選項(xiàng)中,您可以直觀地看到北京時(shí)間。
如果您想添加其他外國(guó)城市,可以單擊上面的按鈕添加它們。你可以使用iPhone的觸摸鍵盤添加一個(gè)世界時(shí)鐘來(lái)顯示世界上其他主要城市和時(shí)區(qū)的時(shí)間。如果你找不到一個(gè)城市,你可以找到一個(gè)主要城市在同一時(shí)區(qū)的城市。
蘋果使用秒表方法
1、解鎖手機(jī),進(jìn)入手機(jī)主人界面。
2、找到時(shí)鐘應(yīng)用程序并打開(kāi)它。
3、這時(shí),我們點(diǎn)擊下面的秒表圖標(biāo)。
4、此時(shí)點(diǎn)擊開(kāi)始,即可計(jì)時(shí)。
5、開(kāi)始計(jì)數(shù)后,我們可以通過(guò)點(diǎn)擊計(jì)數(shù)來(lái)記錄每次的時(shí)間。
6、計(jì)時(shí)器結(jié)束后,我們可以點(diǎn)擊停止。
7、記錄數(shù)據(jù)后,按復(fù)位清除所有數(shù)據(jù)。
網(wǎng)頁(yè)標(biāo)題:ios開(kāi)發(fā)秒表,ios開(kāi)測(cè)表
當(dāng)前路徑:http://chinadenli.net/article20/dsgiico.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、網(wǎng)站改版、網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、面包屑導(dǎo)航、云服務(wù)器
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)