[英]uiprogressview doesn't appear below uitableview in iOS 7
我正在編寫一個使用UIProgressView的程序,該程序以編程方式添加並在程序執行期間隱藏/顯示。 我有以下在iOS 5中可用的代碼。該代碼通過將UIProgressView添加為UITableView的超級視圖的子視圖,在UITableView的“下方”添加了UIProgressView。 當UITableView滾動時,這還將UIProgressView保持在一個位置。
在viewDidLoad中,我設置UIProgressView的框架
UIProgressView * progressBar = [[[UIProgressView alloc]
initWithProgressViewStyle:UIProgressViewStyleBar] retain];
progressBar.hidden = NO;
progressBar.progress = [[NSUserDefaults standardUserDefaults] floatForKey:@"progress"];
//Set up the UIProgressView
frameForProgressBar = CGRectMake(0.0f,
self.tableView.frame.origin.y +
self.tableView.frame.size.height -
progressBar.frame.size.height,
self.tableView.frame.size.width,
progressBar.frame.size.height);
progressBar.frame = frameForProgressBar;
insetsForTableView = UIEdgeInsetsMake(0.0, progressBar.frame.size.height, 0.0, 0.0);
然后當我希望UIProgressView出現時
// Add the Progress bar to the Window
progressBarState = ADD_PROGRESS_BAR;
[self.view.superview addSubview:progressBar];
這樣我就可以看到UIProgressView,更改UITableView的contentInsets。 為了適應iOS 7,我讀到對contentInsets的更改必須在viewWillLayoutSubviews中進行。
-(void) viewWillLayoutSubviews
{
switch (progressBarState)
{
case ADD_PROGRESS_BAR:
// Set the frame of the UITableView to allow the UIProgressView to appear
self.tableView.contentInset = insetsForTableView;
break;
case REMOVE_PROGRESS_BAR:
self.tableView.contentInset = UIEdgeInsetsZero;
break;
default:
break;
}
progressBarState = UNDEFINED_PROGRESS_BAR;
}
我通過調試器運行此代碼,並調用了viewWillLayoutSubviews。 但是,我沒有看到UITableView調整大小,也沒有看到UIProgressView。 我嘗試為UITableView設置框架以使其比屏幕小得多,然后為UIProgressView設置框架,以將其放置在“空”空間中。 但是,我仍然看不到UIProgressView。
有人可以建議為什么我看不到UIProgressView嗎?
謝謝,
傑森·馬佐塔(Jason Mazzotta)
將UIViewController的AutomaticAdjustsScrollViewInsets屬性設置為NO。 由於此屬性可用於iOS 7及更高版本,因此請使用responseToSelector方法檢查可用性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.