??常??吹胶枚鄳?yīng)用push出新界面時,導(dǎo)航欄下方會有一個進度條顯示,所以簡單的實現(xiàn)了一下這個效果。代碼如下:
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, strong) UIProgressView *progressView;
@property (nonatomic, strong) NSTimer *longConnectTimer;
@property (nonatomic, assign) int time;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor greenColor];
self.navigationController.navigationBar.barTintColor = [UIColor orangeColor];
self.navigationItem.title = @"導(dǎo)航欄進度條";
// // 導(dǎo)航欄底部添加進度條
// self.progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, 43, CGRectGetWidth(self.view.frame), 40000)];// 高度設(shè)置無效,默認是2
// 狀態(tài)欄頂部添加進度條
self.progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, -20, CGRectGetWidth(self.view.frame), 40000)];// 高度設(shè)置無效,默認是2
self.progressView.backgroundColor = [UIColor clearColor];// 背景顏色,只有trackTintColor為透明色時,才能看到背景顏色
self.progressView.progressTintColor = [UIColor purpleColor];// 進度部分的顏色
self.progressView.trackTintColor = [UIColor clearColor];// 未進度部分的顏色
// [self.navigationController.navigationBar addSubview:self.progressView];// 導(dǎo)航欄添加進度條方式一
[self.navigationController.navigationBar.layer addSublayer:self.progressView.layer];// 導(dǎo)航欄添加進度條方式二
self.time = 0;
self.longConnectTimer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(longConnectToSocket) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.longConnectTimer forMode:NSRunLoopCommonModes];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)longConnectToSocket {
self.time += 25;
[self.progressView setProgress:(self.time / 100.0) animated:YES];
if (100 == self.time) {
self.time = 0;
}
}
問題一: 不知道大家有沒有更好的實現(xiàn)方式,歡迎留言
問題二:
- 進度條的高度怎么改變??通過設(shè)置transform 屬性progressView.transform = CGAffineTransformMakeScale(1.0f, 5.0f);有問題,就有進度條在進度時,一邊向有進度,一邊向下擴展高度,效果很糟糕。
- 怎樣讓進度條鋪滿整個導(dǎo)航欄的高度(高度64)來顯示進度,但是不遮住導(dǎo)航欄上的標題和按鈕等????