- 軟件開發(fā)的時(shí)候經(jīng)常會(huì)遇到半天才加載出來(lái)數(shù)據(jù)的情況,不管是程序?qū)懙臓€济榨,還是說(shuō)本來(lái)網(wǎng)速比較慢搭儒,一般都都會(huì)給個(gè)提示讓用戶感覺到我們?cè)谂Φ募虞d數(shù)據(jù),iOS可以通過UIActivityIndicatorView
實(shí)現(xiàn)類似的效果昔善。UIActivityIndicatorView提供輕型視圖,會(huì)顯示一個(gè)標(biāo)準(zhǔn)的旋轉(zhuǎn)進(jìn)度輪畔乙,只要添加到程序中君仆,在合適的地方start和stop即可。start的時(shí)候可以吸附在當(dāng)前視圖中牲距,stop的時(shí)候就會(huì)移除~
-
實(shí)現(xiàn)方式如下
self.activityIndicatorView=[[UIActivityIndicatorViewalloc]initWithFrame:CGRectMake(0,0,100,100)]; self.activityIndicatorView.center=self.view.center; [self.activityIndicatorView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray]; [self.activityIndicatorView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge]; [self.activityIndicatorView setBackgroundColor:[UIColorlightGrayColor]]; [self.view addSubview:self.activityIndicatorView]; [self.activityIndicatorView startAnimating];
代碼很簡(jiǎn)單返咱,設(shè)置frame這個(gè)不用講,關(guān)于style的設(shè)置嗅虏,有三種白色和灰色,這兩種的尺寸都是20&20上沐,白色大圖是37&37:
typedef NS_ENUM(NSInteger, UIActivityIndicatorViewStyle)
{ UIActivityIndicatorViewStyleWhiteLarge,
UIActivityIndicatorViewStyleWhite,
UIActivityIndicatorViewStyleGray,};關(guān)閉動(dòng)畫:
dispatch_after(
dispatch_time(DISPATCH_TIME_NOW,
(int64_t)(5*NSEC_PER_SEC)),
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),
^{ [self.activityIndicatorView stopAnimating];
});