在我的瀏覽器應用程序中,如果響應是PDF文件,我使用NSURL連接來下載文件。 當我收到數據時,我會顯示一個UIprogressView來顯示下載狀態。 我想禁用並更改背景視圖的顏色,直到下載完成。更改iOS中視圖的背景顏色
在didReceiveResponse委託我打電話創建progressView和更改的backgroundColor和禁用parentView
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
[self.fileData setLength:0];
self.totalFileSize = response.expectedContentLength;
[self performSelectorOnMainThread:@selector(startProgressView) withObject:nil waitUntilDone:NO];
}
-(void) startProgressView
{
CGSize frameSize = self.view.frame.size;
CGFloat margin = 30.0;
CGPoint center = self.view.center;
topLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, margin, frameSize.width-2*margin, 20.)];
bottomLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, margin, frameSize.width-2*margin, 20.)];
[topLabel setText:@"downloading file"];
[topLabel setCenter:CGPointMake(center.x, center.y - 20.)];
[topLabel setTextAlignment:NSTextAlignmentCenter];
[bottomLabel setText:@"downloadstatus"];
[bottomLabel setCenter:CGPointMake(center.x, center.y + 20.)];
[bottomLabel setTextAlignment:NSTextAlignmentCenter];
self.progressBar = [[UIProgressView alloc] initWithFrame:
CGRectMake(0, margin, frameSize.width-2*margin, 20.)];
[self.progressBar setProgress:0];
[self.progressBar setCenter:center];
[self.view addSubview:topLabel];
[self.view addSubview:(self.progressBar)];
[self.view addSubview:bottomLabel];
/*
CGRect frame = CGRectMake(0.0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
UIView *v = [[UIView alloc] initWithFrame:frame];
[v setBackgroundColor:[[UIColor alloc] initWithRed:255.0
green:0.0
blue:0.0
alpha:0.1]];
[self.view insertSubview:v atIndex:0];
[v release];
*/
[self.view setBackgroundColor: [UIColor colorWithRed:0.0 green:255.0 blue:128.0/255 alpha:0.5]];
[self.view setUserInteractionEnabled:NO];
}
的方法我試過設置背景顏色,甚至將有顏色,但背景顏色不會改變一個新的觀點。 有人可以指出是否有任何我缺少的東西。
除了顏色設置(你看到兩個標籤和進度條),其他所有工作都可以嗎? – rdelmar
是除背景顏色外的其他一切作品。我找出了原因。 viewcontroller(self.view)的主視圖包含3個以上的子視圖,並且更改self.view的背景顏色由於子視圖而不可見。 – codemaster