在 iOS 13 中,模态视图 Controller 在呈现时有一个新的行为。我发现内置的 App Photo 呈现了一个更小的 Model View Controller 。
如何呈现一个像这样的自定义尺寸的viewController,并且可以滑动到更大的高度?
系统照片应用程序的图片截图。
最佳答案
是的,可以在 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/