滚动时UITableView被切断了吗?(UITableView cut off when scrolling?)

我刚才意识到如果我使用这段代码只绕过我的UITableView的前2个边缘:

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:thetableView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10.0, 10.0)]; // Create the shape layer and set its path CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = thetableView.bounds; maskLayer.path = maskPath.CGPath; thetableView.layer.mask = maskLayer;

如果我向下滚动到我在Interface Builder中创建的UITableView框架下面的任何内容,我的tableview内容将被切断。 虽然如果我把这个代码拿出来,一切都很好。

有没有办法充分利用两个世界的优势,我可以围绕顶角,原始框架下面的内容不会被切断?

谢谢!

I just realized that if I use this code to round only the top 2 edges of my UITableView:

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:thetableView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10.0, 10.0)]; // Create the shape layer and set its path CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = thetableView.bounds; maskLayer.path = maskPath.CGPath; thetableView.layer.mask = maskLayer;

My tableview content will get cut off if I scroll down to anything that was below the frame of the UITableView that I made in Interface Builder. Although if I take this code out, everything is fine.

Is there a way to get the best of both worlds where I can round the top corners and the content below the original frame doesn't get cut off?

Thanks!

最满意答案

这是解决方案。 将表视图包含在外部UIView中(与表视图完全相同,并且在封闭视图中将表视图设置为0,0)。 然后将出口连接到该封闭视图并在其上设置圆角顶角。

我认为这是Apple的一个错误。

Here is the solution. Enclose your table view in an outer UIView (exactly the same size as the table view, and with the table view at 0,0 in the enclosing view). Then hook up an outlet to that enclosing view and set rounded top corners on it.

I think this is a bug on Apple's part.

滚动时UITableView被切断了吗?(UITableView cut off when scrolling?)

我刚才意识到如果我使用这段代码只绕过我的UITableView的前2个边缘:

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:thetableView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10.0, 10.0)]; // Create the shape layer and set its path CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = thetableView.bounds; maskLayer.path = maskPath.CGPath; thetableView.layer.mask = maskLayer;

如果我向下滚动到我在Interface Builder中创建的UITableView框架下面的任何内容,我的tableview内容将被切断。 虽然如果我把这个代码拿出来,一切都很好。

有没有办法充分利用两个世界的优势,我可以围绕顶角,原始框架下面的内容不会被切断?

谢谢!

I just realized that if I use this code to round only the top 2 edges of my UITableView:

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:thetableView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10.0, 10.0)]; // Create the shape layer and set its path CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = thetableView.bounds; maskLayer.path = maskPath.CGPath; thetableView.layer.mask = maskLayer;

My tableview content will get cut off if I scroll down to anything that was below the frame of the UITableView that I made in Interface Builder. Although if I take this code out, everything is fine.

Is there a way to get the best of both worlds where I can round the top corners and the content below the original frame doesn't get cut off?

Thanks!

最满意答案

这是解决方案。 将表视图包含在外部UIView中(与表视图完全相同,并且在封闭视图中将表视图设置为0,0)。 然后将出口连接到该封闭视图并在其上设置圆角顶角。

我认为这是Apple的一个错误。

Here is the solution. Enclose your table view in an outer UIView (exactly the same size as the table view, and with the table view at 0,0 in the enclosing view). Then hook up an outlet to that enclosing view and set rounded top corners on it.

I think this is a bug on Apple's part.