CustomSizeController
概述
CustomSizeController 是 UIPresentationController 的子类,允许任何 UIViewController 具有自定义大小。
用法
import CustomSizeController
将这两个扩展添加到您的 view controller 中
extension ViewController: UIViewControllerTransitioningDelegate {
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
let customSizePC = CustomSizeController(presentedViewController: presented, presenting: presenting)
customSizePC.sizeDelegate = self
//customSizePC.isDisabledTapOutside = true
return customSizePC
}
}
extension ViewController: CustomSizeControllerDelegate {
func frameOfPresentedView(in containerViewFrame: CGRect) -> CGRect {
return CGRect(origin: CGPoint(x: 0, y: containerViewFrame.height / 4), size: CGSize(width: containerViewFrame.width, height: containerViewFrame.height / (4/3)))
}
}
从 frameOfPresentedView(in:)
函数返回小 view controller 的 frame。
如何展示 view controller
从代码示例
let vc = storyboard?.instantiateViewController(withIdentifier: "SmallVC") as! SmallViewController
vc.modalPresentationStyle = .custom
vc.transitioningDelegate = self
present(vc, animated: true, completion: nil)
来自Storyboard
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let smallVC = segue.destination as? SmallViewController {
smallVC.modalPresentationStyle = .custom
smallVC.transitioningDelegate = self
}
}
外部点击禁用 dismiss
customSizePC.isDisabledTapOutside = true
示例
该项目包含一个示例项目。要运行示例项目,首先克隆此仓库,然后从 Example 目录运行 pod install
。
最低要求
- Xcode 9
- iOS 9.3
使用 CocoaPods 安装
CustomSizeController 可通过 CocoaPods 获取。要安装,只需将以下行添加到您的 Podfile 中
pod 'CustomSizeController'
作者
Warif Akhand Rishi, [email protected]
许可协议
CustomSizeController 以 MIT 许可协议提供。更多信息请参阅 LICENSE 文件。