Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用cornerRadius四舍五入所有拐角都有效,但如果我只使用底部两个拐角,则在UITableView上滚动会中断_Ios_Objective C_Uitableview_Uiviewcontroller_Calayer - Fatal编程技术网

Ios 使用cornerRadius四舍五入所有拐角都有效,但如果我只使用底部两个拐角,则在UITableView上滚动会中断

Ios 使用cornerRadius四舍五入所有拐角都有效,但如果我只使用底部两个拐角,则在UITableView上滚动会中断,ios,objective-c,uitableview,uiviewcontroller,calayer,Ios,Objective C,Uitableview,Uiviewcontroller,Calayer,项目示例: 我有一个子视图控制器,其中有一个UITableView,这个视图控制器位于另一个视图控制器的顶部。我想给它的底部圆角(但只有底部) 在我的UITableView子类中,我有以下代码来绕过底角 - (id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (self) { UIBezierPath *maskPath; maskPat

项目示例:

我有一个子视图控制器,其中有一个UITableView,这个视图控制器位于另一个视图控制器的顶部。我想给它的底部圆角(但只有底部)

在我的UITableView子类中,我有以下代码来绕过底角

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        UIBezierPath *maskPath;
        maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(5.0, 5.0)];

        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = self.bounds;
        maskLayer.path = maskPath.CGPath;
        self.layer.mask = maskLayer;

        self.backgroundColor = [UIColor colorWithRed:0.169 green:0.169 blue:0.169 alpha:1];
    }
    return self;
}
这确实使它们圆化了,但当我滚动桌子视图时,它会进一步向上移动,并降低高度(至少看起来是这样)

但是,如果我只使用
self.layer.cornerRadius=5.0
它完全可以正常工作


有人知道为什么会出现这种情况吗?

UIScrollView,以及子类UITableView,实际上是通过更改其呈现内容的边界来呈现内容的。我的猜测是,将掩码添加到UITableView的层实际上是将掩码添加到视图中的内容,而不是您可能想象的容器

为什么“self.layer.cornerRadius=5.0”有效,而您的方法无效,我不确定

对于类似的请求,已经给出了一种更有效的方法,因此我将指导您:


基本上,建议将UITableView放入容器中,并将掩码添加到容器中。我相信这会很好。这可能不是一个确切的答案。但我会给你一个解决办法

看看这个问题和答案

这会给你我试过的线索

正如在那个问题中所解释的,添加
tableView
掩码对您不起作用,因为它会随着您所解释的
tableView
一起移动。 因此,我尝试在您的
DropDownViewController
中为
tableView
添加另一个
superview
,并为其添加一个插座

然后我在
DropDownViewController
中的
viewdiload
中更改了您的代码,为
tableView
的当前
superview
添加了
掩码

UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.tableSuperView.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(5.0, 5.0)];

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.view.bounds;
maskLayer.path = maskPath.CGPath;
self.tableSuperView.layer.mask = maskLayer;
就这样。它起作用了。当我将
tableView
滚动到末尾时,我发现了一个不需要的行为。发生这种情况的原因是
tableView
bounce动画。如果删除该动画,则可以继续


很高兴知道你的意见和结果。

你说的“更进一步”是什么意思?“它”是什么?牢房?面具?你在使用自动布局吗?如果是这样的话,一个约束可能会调整单元格层的大小。我不记得系统是否自动调整图层的遮罩图层大小。对不起。很明显,当我滚动时,tableview似乎向上移动,而不是滚动视图。下面是一个示例项目,其中我根据答案的请求在其视图控制器中屏蔽表视图的包含视图:但如果您只需将其移动到表视图的
initWithCoder
,它就会产生我们所说的效果。下面是一个示例项目:我尝试在该视图控制器的
viewDidLoad
中添加将遮罩设置为
self.view.layer
,但它仍然不起作用。您也可以将遮罩设置为具有表格视图边框的大小,然后在
scrollViewDidScroll:
中调整遮罩的位置,使其固定在表格视图的可见部分。