use*_*861 5 transition modal-dialog ios
我有一个视图控制器VC1,从一些其他VC0模拟全屏显示.在我的故事板中,我有一个从VC1到VC2的模态segue也在全屏显示.在我的应用程序中,我可以通过VC0在VC1上清楚地看到VC2,因为它们的某些部分视图是透明的.完善.
但是,我要多次重用VC2,所以我不想为我的故事板中的每个控制器设置一个segue,所以我想以编程方式完成同样的事情.但是,当我调用presentViewController:animated:VC1中的完成以呈现VC2时,VC1的视图在模态转换完成时消失.当VC2被解除时,VC1的视图在转换动画完成时重新出现.
如何以编程方式获得与使用storyboard segue时相同的效果?
ama*_*ard 17
let newView = self.storyboard!.instantiateViewControllerWithIdentifier("NewViewController") as! NewViewController
newView.modalPresentationStyle = UIModalPresentationStyle.OverFullScreen
self.presentViewController(newView, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
ale*_*kop 11
您只能在可见的控制器上呈现,通常是rootViewController. 但是当有一个模态呈现的控制器时,它覆盖了根控制器,所以你不能使用它。但是你可以在模态上呈现,虽然可以访问rootViewController.prsentedViewController。这是一些代码:
let rootVC = window?.rootViewController
let presentingVC = (rootVC?.presentedViewController ?? rootVC)
presentingVC?.present(myController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
您无需更改modalPresentationStyle.
您需要modalPresentationStyle将呈现的控制器的属性设置为UIModalPresentationOverFullScreen.在你打电话之前设置那个属性presentViewController:animated:completion.
| 归档时间: |
|
| 查看次数: |
14666 次 |
| 最近记录: |