swift - 如何将 ViewController 呈现为没有背景阴影的模态表
问题描述
有没有什么方法可以将 ViewController 呈现为没有背景阴影的模态表,如下面的第一张图片所示,使用 swift. 有没有简单的方法或者我们需要编写自定义 UIPresentationController?[![所需输出][1]][1]
[1]: https://i.stack.imgur.com/QAEEn.png ![在此处输入图片描述]( https://i.stack.imgur.com/q4JD5.jpg )
解决方案
您可以根据需要使用较小尺寸的视图控制器。首先添加一个类。
class SmallSizePresentationController : UIPresentationController {
override var frameOfPresentedViewInContainerView: CGRect {
get {
guard let theView = containerView else {
return CGRect.zero
}
return CGRect(x: 0, y: theView.bounds.height * (281 / 896), width: theView.bounds.width, height: theView.bounds.height)
}
}
}
然后,当您想要呈现这种类型的视图控制器时,只需添加当前视图控制器的扩展。
extension YourCurrentViewController: UIViewControllerTransitioningDelegate {
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
return SmallSizePresentationController(presentedViewController: presented, presenting: presenting)
}
}
然后像这样展示你的新视图控制器
let VC = withoutShadowVC()
VC.transitioningDelegate = self
VC.modalPresentationStyle = .custom
self.present(VC, animated: true, completion: nil)
您可以修改视图控制器高度。
推荐阅读
- android - 如何使用 com.android.dialer.telecom.TelecomUtil
- node.js - 无法让 FFMPEG buildpack 在 Heroku Node.js 服务器中工作(使用 Fluent-FFMPEG)
- json - 如何在python中对嵌套的json进行数据框化?json 是递归的,具有相同的键名,需要将数据框化为同一列
- javascript - 使用 jquery.val() 函数返回 undefined 并且 javaScript querySelector 返回 null 但我希望 undefined 作为返回值
- javascript - 解释 d3 定心力
- android - 是否可以访问适配器中两个不同布局文件的 id?
- r - 如何强制 ld 链接到静态库
- linux - 解压大量小文件并再次压缩以提高效率并避免 S3 API 成本
- css - 图片下方或图片上的按钮 *ngFor 循环
- swift - 使用自定义逻辑序列化包含非 Codable 内置类型的状态