简体   繁体   English

改变模态视图的角半径 controller

[英]Change cornerRadius of the modal view controller

My goal is to increase corner radius of the modally presented controller to 25. As you can see in the picture it has rounded corners by default but I need them to have greater radius.我的目标是将模态呈现的 controller 的角半径增加到 25。正如您在图片中看到的,默认情况下它具有圆角,但我需要它们具有更大的半径。 I've tried rounding corners by accessing controllers view, but it's not working.我尝试通过访问控制器视图来圆角,但它不起作用。

view.layer.cornerRadius = 25

I haven't found any mention of it in the apple documentation, is there any way to make it work?我没有在苹果文档中找到任何提及,有什么办法让它工作吗? Is this even possible?这可能吗?

在此处输入图像描述

You can get the effect by changing your presented view controller's top view's background to clear which hides the view where the presenter is rounding corners.您可以通过更改呈现的视图控制器的顶视图的背景来清除哪个隐藏了演示者圆角的视图来获得效果。 Then just round the corners of the next top view to the desired amount.然后将下一个顶视图的角圆角到所需的量。

you can't, that's a custom presentation controller created by apple that is a protected/private API to conform to new design standards throughout the apple eco system for ios 13 and beyond.你不能,那是由苹果创建的自定义演示 controller,它是受保护/私有的 API,以符合整个苹果生态系统中 ios 的新设计标准。 what you can do instead is create your own subclass implementation of UIPresentationController and then round the corners to whatever corner radius you wish.你可以做的是创建你自己的 UIPresentationController 子类实现,然后将角圆角到你想要的任何角半径。 subclassing UIPresentationController with pan gestures that interact well with even first degree nesting of scroll views is a daunting task, however.然而,使用平移手势子类化 UIPresentationController 甚至可以很好地与滚动视图的一级嵌套交互,这是一项艰巨的任务。 I'd check out some example code for this before you try to override the default since doing so will land you in a black hole of chaos pretty quickly unless you're well versed in UIKit, Foundation, and delegation with ios.在您尝试覆盖默认值之前,我会查看一些示例代码,因为这样做会使您很快陷入混乱的黑洞,除非您精通 UIKit、Foundation 和 ios 的委托。

I see, that it's probably too late for you, but maybe it will be useful to others.我知道,这对您来说可能为时已晚,但也许对其他人有用。 I used layer(gradient) with mask, but I think, you can modify it as you like我使用了带蒙版的图层(渐变),但我认为,你可以随意修改它

    self.view.backgroundColor = .clear
    let mask = CAShapeLayer()

    mask.path = UIBezierPath(roundedRect: tableView.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize.init(width: 25, height: 25)).cgPath

    // You can use with layer of viewConroller's view
    self.view.layer.backgroundColor = UIColor.green.cgColor
    self.view.layer.mask = mask

    // And gradient background for VC
    let gradient = CAGradientLayer()
    gradient.colors = [UIColor.green.cgColor, UIColor.blue.cgColor]
    gradient.frame = view.bounds
    gradient.mask = mask
    self.view.layer.insertSublayer(gradient, at: 0)


    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM