2012-12-12 80 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