Ios UITableView-底部圆角

Ios UITableView-底部圆角,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我试图在UITableView上实现底部圆角 override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() MyUtils.roundCornersOnView(myUIView, rectCorner: [.TopLeft, .TopRight], radius: 15) MyUtils.roundCornersOnView(myTableView, rectCorner: [

我试图在
UITableView
上实现底部圆角

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
        MyUtils.roundCornersOnView(myUIView, rectCorner: [.TopLeft, .TopRight], radius: 15)
        MyUtils.roundCornersOnView(myTableView, rectCorner: [.BottomLeft, .BottomRight], radius: 15)
} 
我使用了下面的代码片段,它存在于MyUtils.m中-

/*
* To get rounded corners of view.
*/
+ (UIView *)roundCornersOnView:(UIView *)view rectCorner:(UIRectCorner)corner radius:(float)radius
{
   UIView *roundedView = view;
   UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:roundedView.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(radius, radius)];
   CAShapeLayer *maskLayer = [CAShapeLayer layer];
   maskLayer.frame = roundedView.bounds;
   maskLayer.path = maskPath.CGPath;
   roundedView.layer.mask = maskLayer;
   return roundedView;
}
然后,我从swift文件调用了上面的
MyUtils
方法,将两个视图的拐角处对齐。一个是
UIView
,另一个是
UITableView

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
        MyUtils.roundCornersOnView(myUIView, rectCorner: [.TopLeft, .TopRight], radius: 15)
        MyUtils.roundCornersOnView(myTableView, rectCorner: [.BottomLeft, .BottomRight], radius: 15)
} 
UIView
没有问题,在
UITableView
的情况下,我可以在底部看到我想要实现的底部圆角,但之后
UITableView
开始滚动,而不是滚动其内容


通常,
UITableView
的内容会滚动,但应用此
UITableView
后,会启动滚动,可能是
UITableView的后台正在滚动。

覆盖tableView的屏蔽层更改了它的tableViewWrapper属性,这引入了一种奇怪的行为,因此我们需要添加一个容器视图并实现屏蔽:

@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UIView *container;
@property (weak, nonatomic) IBOutlet UITableView *testTable;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    CAShapeLayer * maskLayer = [CAShapeLayer layer];
    // manually configuring the mask rect will be the best way to set it rather than setting it in viewDidLayoutSubviews or viewDidAppear that can be called again when view is dismissed or popback.
    CGRect rect = CGRectMake(0, 40, [UIScreen mainScreen].bounds.size.width - 40, [UIScreen mainScreen].bounds.size.height - 204);

    maskLayer.path = [UIBezierPath bezierPathWithRoundedRect: rect byRoundingCorners: UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii: (CGSize){10.0, 10.}].CGPath;

    self.container.layer.mask = maskLayer;
    self.container.clipsToBounds = YES;

}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 15;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

    cell.textLabel.text = [NSString stringWithFormat:@"%ld", (long)indexPath.row];

    return cell;
}

@end
@界面视图控制器()
@属性(弱、非原子)IBUIView*容器;
@属性(弱、非原子)IBUITableView*测试表;
@结束
@实现视图控制器
-(无效)viewDidLoad{
[超级视图下载];
//加载视图后,通常从nib执行任何其他设置。
CAShapeLayer*maskLayer=[CAShapeLayer层];
//手动配置mask rect是设置它的最佳方式,而不是在viewDidLayoutSubviews或ViewDidDisplay中进行设置,当视图被取消或弹出时,可以再次调用viewDidLayoutSubviews或ViewDidDisplay。
CGRect rect=CGRectMake(0,40,[UIScreen mainScreen].bounds.size.width-40,[UIScreen mainScreen].bounds.size.height-204);
maskLayer.path=[UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRightCornerRadii:(CGSize){10.0,10.}].CGPath;
self.container.layer.mask=maskLayer;
self.container.clipstobunds=是;
}
-(NSInteger)表格视图中的节数:(UITableView*)表格视图{
返回1;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节{
返回15;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:@“cell”];
cell.textLabel.text=[NSString stringWithFormat:@“%ld”,(长)indexPath.row];
返回单元;
}
@结束

将clipToBounds应用于myTableView,使超出myTableView范围的内容不可见。@nferocious76感谢您对此进行研究,但不确定的是,这不起作用。可以给我看一些该部分的屏幕截图吗?请加入这个房间:请检查文件:)我们可以将UIView设置为Table的背景视图,我们不能在不引入新的父视图的情况下更新该背景视图吗?不。背景视图在滚动时会改变其偏移量,尽管您也可以手动调整其大小,但它位于tableView内容的后面,因此您的角将位于下方且无用。