2012-12-12 76 views
2

我正在開發一個小的iOS組件,我有一個半透明的視圖與子視圖的問題。這是我的情景:
- 一個視圖使用[UIColor colorWithRed:green:blue:alpha]
半透明背景 - 有點UITableView,用alpha = 1.0,添加作爲一個子視圖到半透明,
- 其他一些子視圖tableview作爲subview在半透明視圖

一切正常但是當UITableView向上或向下滾動時,問題會上升,實際上UITableView周圍的半透明視圖的區域失去了透明度,變得比其原始背景顏色更暗。

下面是一個圖片說明問題:

看具有兩個箭頭的空間...

誰能幫我解決這個問題?
非常感謝您的關注!

更新:
一些代碼:

_alertBg = [[UIView alloc] initWithFrame:CGRectZero]; 
_alertBg.backgroundColor = self.backgroundColor; 
_alertBg.frame = CGRectMake((_bgView.frame.size.width - 240)/2, (_bgView.frame.size.height - 260)/2, 240, 260); 
_alertBg.layer.cornerRadius = 8.0; 
_alertBg.layer.borderWidth = 2.0; 
_alertBg.layer.borderColor = self.borderColor.CGColor; 
_alertBg.layer.shadowColor = [UIColor grayColor].CGColor; 
_alertBg.layer.shadowOffset = CGSizeMake(0, 3); 
_alertBg.layer.shadowOpacity = 0.8; 
_alertBg.layer.masksToBounds = YES; 
[_bgView addSubview:_alertBg]; 

_table = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; 
_table.frame = CGRectMake(10, _titleLabel.frame.origin.y + _titleLabel.frame.size.height + 12, _alertBg.frame.size.width - 20, 150); 
_table.layer.cornerRadius = 6.0; 
_table.layer.masksToBounds = YES; 
_table.delegate = self; 
_table.dataSource = self; 
[_alertBg addSubview:_table]; 

從上面的代碼,self.backgroundColor是一樣的東西[UIColor colorWithRed:0 green:0 blue:1 alpha:0.7]

+0

可能有助於瞭解如何創建這些意見的CGRect信息。 IB或計劃建設? – Bejmax

+0

一切都是用簡單的看法和一些QuartzCore代碼,沒有IB或做的CGRect ...我編輯的職位,並添加一些代碼 – matteodv

+0

@matteodv請加cellForRawAtIndexPath方法並發表評論 –

回答

1

我把可用的代碼放在一個測試項目中,並且遇到同樣的問題。評論出_alertBg.layer.shadowOpacity = 0.5;解決了我的問題。也許有人可以澄清爲什麼這是一個問題,我對QuartzCore的經驗有限。

編輯:好吧,更接近真正的原因。看起來,如果你沒有設置_alertBg.layer.shadowPath屬性,當你滾動表格時會發生各種瘋狂的事情(我的猜測是表格滾動調用了_alertBg的重繪,陰影重繪也被快速地連續調用很多次,你會得到那些視覺神器)。

添加shadowPath修復的問題,所以對於_alertBg層代碼應該如下:

_alertBg.layer.cornerRadius = 8.0; 
_alertBg.layer.borderWidth = 2.0; 
_alertBg.layer.borderColor = [UIColor colorWithRed:0 green:0 blue:1 alpha:0.7].CGColor; 
_alertBg.layer.shadowColor = [UIColor grayColor].CGColor; 
_alertBg.layer.shadowOffset = CGSizeMake(0, 5); 
_alertBg.layer.shadowOpacity = 0.8; 
_alertBg.layer.shadowPath = [UIBezierPath bezierPathWithRect:_alertBg.bounds].CGPath; 
_alertBg.layer.masksToBounds = YES; 

剛剛修復shadowPath根據自己的喜好,你應該準備好了。

PS:在我的Google任務中,我找到了關於陰影的this excellent blog post,這可能有幫助。

+0

謝謝你這麼多......這正是我一直在尋找,我的問題解決了!再次感謝! – matteodv

0

也許匹配的tableView與_alertBg背景顏色?

+0

的一些代碼,不幸的是這並沒有解決問題... – matteodv

0

它可能是dequeueReusableCellWithIdentifier的問題。

只是試試這個...,在UITableViewController委託方法

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil]; 

cellForRowAtIndexPath方法設置dequeueReusableCellWithIdentifiernil像波紋管也看到我這個答案可能是你可以從中得到一些想法..

iPhone Hide/Show labels in Uitableview cell