【问题标题】:Rounding corners of UIModalPresentationFormSheetUIModalPresentationFormSheet 的圆角
【发布时间】:2014-01-03 18:32:45
【问题描述】:

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

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

- (void)viewWillLayoutSubviews{

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

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

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

self.view.layer.masksToBounds = YES;

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

谢谢,

【问题讨论】:

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


    【解决方案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】:

    使用这个,它会去除阴影

    self.view.layer.masksToBounds = YES;
    

    【讨论】:

    • 嗨,不幸的是,这似乎不起作用,上面显示了相同的结果。
    • 是的,我也是在 shan 回答的时候同时回答的,但相差几秒钟。我没注意到他
    【解决方案3】:
    - (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 的圆角半径。

    【讨论】:

    • 对于 iOS8,尝试使用 self.view.layer。
    • 这对我有用。技巧是在“viewWillLayoutSubviews”中设置这些东西
    【解决方案4】:

    原来你需要对superview进行四舍五入,对superview进行屏蔽;

    [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;
    }
    

    感谢山的帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多