在對新浪微博進行下拉刷新操作時,會從頂部的導(dǎo)航欄下面慢慢向下彈出一條顯示刷新獲取到的微博數(shù)的橙色控件,控件懸停1秒,然后向上回到導(dǎo)航欄下面,然后消失。因為該控件不會隨tableView的滾動而滾動,因此該控件不是添加到tableView上的,所以應(yīng)當(dāng)將該控件添加到導(dǎo)航欄。該控件可以通過最簡單的Label添加背景圖片實現(xiàn)。

代碼實現(xiàn):
<pre>
<code>//顯示最新微博數(shù)量</code>
<code>-(void)showNewStatusCount:(int *)count{</code>
<code> //創(chuàng)建Label</code>
<code> UILabel *label=[[UILabel alloc]init];</code>
<code> //設(shè)置Label的背景圖片</code>
<code> label.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"timeline_new_status_background"]];</code>
<code> label.width=[UIScreen mainScreen].bounds.size.width;</code>
<code> label.height=35;</code>
<code> //設(shè)置其他屬性</code>
<code> if (count==0) {</code>
<code> label.text=@"沒有新的微博數(shù)據(jù),請稍后再試";</code>
<code> }else{</code>
<code> label.text=[NSString stringWithFormat:@"共有%d條新的微博數(shù)據(jù)",count];</code>
<code> }</code>
<code> label.textColor=[UIColor whiteColor];</code>
<code> label.font=[UIFont systemFontOfSize:16];</code>
<code> label.textAlignment=NSTextAlignmentCenter;</code>
<code> label.y=64-label.height;</code>
<code> //將label添加到導(dǎo)航欄控制器的view中,并且是蓋在導(dǎo)航欄下邊</code>
<code> [self.navigationController.view insertSubview:label belowSubview:self.navigationController.navigationBar];</code>
<code> //動畫設(shè)置</code>
<code> CGFloat duration=1.0; //通過定義動畫執(zhí)行的時間來控制動過程的速度</code>
<code> [UIView animateWithDuration:duration animations:^{</code>
<code> label.transform=CGAffineTransformMakeTranslation(0, label.height);</code>
<code> } completion:^(BOOL finished) {</code>
<code> CGFloat delay=1.0; //定義控件懸停的時間</code>
<code> [UIView animateWithDuration:duration delay:delay options:UIViewAnimationOptionCurveLinear animations:^{</code>
<code> label.transform=CGAffineTransformIdentity;</code>
<code> } completion:^(BOOL finished) {</code>
<code> //動畫控件執(zhí)行完整個過程后將其從父視圖移除</code>
<code> [label removeFromSuperview];</code>
<code> }];</code>
<code> }];</code>
<code>}</code>
</pre>
在程序執(zhí)行刷新的代碼處調(diào)用該方法實現(xiàn)該效果。
小結(jié)
以上方法是針對近期自學(xué)新浪微博項目的一點小小總結(jié),行筆簡陋,如有錯誤,望指正。