UIModalPresentationFormSheet的四舍五入

时间:2013-12-16 11:23:17

标签: ios objective-c uiview rounded-corners uimodalpresentationstyle

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

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

- (void)viewWillLayoutSubviews{

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

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

enter image description here

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

self.view.layer.masksToBounds = YES;

然而,这仍然具有与上述相同的效果。

谢谢,

4 个答案:

答案 0 :(得分: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的角半径。

答案 1 :(得分: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 

 }


答案 2 :(得分:1)

使用它,它将删除阴影

self.view.layer.masksToBounds = YES;

答案 3 :(得分: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;
}

感谢您的帮助Shan