3

如果这是一个明显的问题,请原谅我,我相对较新。

我有一个模态视图,我设置了自定义大小和圆角:

- (void)viewWillLayoutSubviews{

    [super viewWillLayoutSubviews];
    self.view.superview.bounds = CGRectMake(0, 0, 600, 450);
    self.view.layer.cornerRadius  = 60.0;  
}

但是我发现当我绕过视图角落时,我会在它的边缘出现这种灰色(好像它后面还有其他东西):(见图)。

在此处输入图像描述

如何去除这些灰色边缘,使其像正常一样显示背景内容?我试过添加

self.view.layer.masksToBounds = YES;

但是,这仍然会产生与上述相同的效果。

谢谢,

4

4 回答 4

15
- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    self.view.superview.bounds = CGRectMake(0, 0, 600, 450);
    self.view.superview.layer.cornerRadius  = 60.0;   
    self.view.superview.layer.masksToBounds = YES;  
}

我认为你应该设置 superView 的角半径。

于 2013-12-16T13:37:39.047 回答
1

使用它,它将消除阴影

self.view.layer.masksToBounds = YES;
于 2013-12-16T11:32:26.537 回答
1

事实证明,您需要舍入超级视图并掩盖超级视图;

[self.view superview].layer.cornerRadius = 30.0f;
[self.view superview].layer.masksToBounds = YES;

所以最后它看起来像这样:)

- (void)viewWillLayoutSubviews{
    //setup custom size modal view
    [super viewWillLayoutSubviews];
    self.view.superview.bounds = CGRectMake(0, 0, 600, 450);
    [self.view superview].layer.cornerRadius = 30.0f;
    [self.view superview].layer.masksToBounds = YES;
}

谢谢你的帮助山

于 2013-12-16T13:37:47.213 回答
1

像这样使用

 - (void)viewWillLayoutSubviews
 {

  [super viewWillLayoutSubviews];
  self.view.superview.bounds = CGRectMake(0, 0, 600, 450);
  self.view.layer.cornerRadius  = 60.0;   
  self.view.layer.masksToBounds = YES; //add this line 

 }


于 2013-12-16T11:31:37.763 回答