【发布时间】:2012-03-20 09:10:17
【问题描述】:
我知道如何在单个视图中绘制线条/矩形。但在这种情况下我迷路了:
我有一个UIView A 和一个UITableView B。A 被添加到 viewController 的视图中,B 被添加到 A。如你所知,UITableView 没有边框,因此我尝试沿着边界画线B。
下面是我如何组织这些视图的代码:
if (_tableView) {
[_tableView release];
_tableView = nil;
}
UITableView * temp = [[UITableView alloc] initWithFrame:tableRect style:UITableViewStylePlain];
temp.delegate = self;
temp.dataSource = self;
temp.showsHorizontalScrollIndicator = NO;
temp.alwaysBounceHorizontal = NO;
self.table = temp;
[temp release];
temp = nil;
[self.table setContentInset:UIEdgeInsetsMake(1, 2, 0, 2)];
[_transparencyView addSubview:self.table];
[self.parentViewController.view addSubview:_transparencyView];
[_transparencyView setNeedsDisplayInRect:tableRect];
_transparencyView是ZJTransparencyView的一个实例,继承自UIView,其实现文件如下:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
NSLog(@"%s:%@",__func__,NSStringFromCGRect(rect));
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor cyanColor].CGColor);
CGContextSetLineWidth(context, 2);
CGContextStrokeRect(context, rect);
}
我遇到的问题是:
当我添加表格视图并调用setNeedsDisplayInRect: 时,发送到drawRect: 的矩形始终为{0,0,320,460}。似乎 tableRect 没有效果。我不知道为什么会这样。
谁能帮帮我?
【问题讨论】: