【发布时间】:2015-03-02 23:23:41
【问题描述】:
我有两个视图控制器,我想展示第一个 VC 的视图控制器(VC)。第二个VC的尺寸较小。我想在第一个视图控制器上显示第二个视图控制器。就像一个弹出窗口。你可以想象,如果我们添加另一个从下到上滑动但停在导航栏的视图控制器。
这是我的代码:
@IBAction func showSecondVC(sender: AnyObject) {
let secondViewController = storyboard?.instantiateViewControllerWithIdentifier("SecondViewController") as! SecondViewController
secondViewController.view.frame = CGRect(origin: CGPoint(x: view.frame.origin.x, y: header.frame.height), size: CGSize(width: view.frame.width, height: view.frame.height - header.frame.height))
secondViewController.definesPresentationContext = true
secondViewController.providesPresentationContextTransitionStyle = true
secondViewController.modalPresentationStyle = UIModalPresentationStyle.CurrentContext
self.presentViewController(secondViewController, animated: true, completion:nil)
}
你可以看到我为secondViewController设置了框架。我希望它将与此帧一起使用,但如果我添加完成块并在动画后显示它的帧,它将与第一个 View Controller 相同。
编辑
我还想提一下,我尝试将其设为纵向。
【问题讨论】:
-
我为此做了一个 Github repo BonsaiController。
标签: ios iphone swift uiviewcontroller presentviewcontroller