gpt4 book ai didi

objective-c - 在 iOS 13 中以自定义高度呈现模态框

转载 作者:行者123 更新时间:2023-12-03 18:46:24 25 4
gpt4 key购买 nike

在 iOS 13 中,模态视图 Controller 在呈现时有一个新的行为。我发现内置的 App Photo 呈现了一个更小的 Model View Controller 。

如何呈现一个像这样的自定义尺寸的viewController,并且可以滑动到更大的高度?

smaller height

larger height

系统照片应用程序的图片截图。

最佳答案

是的,可以在 iOS 13 中以自定义高度呈现模式。您只需将以下代码添加到您的演示模式中

 override func updateViewConstraints() {
self.view.frame.size.height = UIScreen.main.bounds.height - 150
self.view.frame.origin.y = 150
self.view.roundCorners(corners: [.topLeft, .topRight], radius: 10.0)
super.updateViewConstraints()
}

extension UIView {
func roundCorners(corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
layer.mask = mask
}
}

关于objective-c - 在 iOS 13 中以自定义高度呈现模态框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58007671/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com