-1
我想展示一個ViewController(嵌入在NavigationController中)從一個TableViewController內的按鈕。呈現的ViewController應該是TableViewController的一半高度。我試過下面的代碼,但它似乎並沒有工作(Swift 3)。有人可以幫助嗎?謝謝!目前Modally非調整大小視圖正確
class AddNewRecipeTableViewController: UITableViewController, UIViewControllerTransitioningDelegate {
@IBAction func popUpTest(_ sender: Any) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let pvc = storyboard.instantiateViewController(withIdentifier: "popUpTest") as! UINavigationController
pvc.modalPresentationStyle = UIModalPresentationStyle.custom
pvc.transitioningDelegate = self
self.present(pvc, animated: true, completion: nil)
}
func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController!, sourceViewController source: UIViewController) -> UIPresentationController? {
return HalfSizePresentationController(presentedViewController: presented, presenting: presentingViewController)
}
}
class HalfSizePresentationController : UIPresentationController {
override var frameOfPresentedViewInContainerView : CGRect {
return CGRect(x: 0, y: 0, width: containerView!.bounds.width, height: containerView!.bounds.height/2)
}
}
謝謝你,工作! – Albert
非常好,謝謝你回報。 – matt