97 modalviewcontroller ios swift swift2 swift2.1
我知道这个主题很受欢迎,但我在编程语言中有点问题,事实是我仍然不明白我把代码放在哪里.好吧,我会告诉整个案子:
我试图使模态Swift与正常情况略有不同:通过单击按钮,ViewController在屏幕上显示(按照模态类型),但具有透明背景.仅显示带标签的蓝色视图.当呈现此ViewController时,它具有透明背景,但是一旦完成转换,它将保持黑色背景.已经停用了opaque选项,并测试了一些选项,但没有这个故障排除.
有人能帮帮我吗?
视频是在案例模拟器中进行的测试(https://www.youtube.com/watch?v=wT8Uwmq9yqY).
我开始使用swift,我仍然很失落如何在Xcode中编程,我读了一个问题的答案,该问题有以下代码来解决这个问题:
self.presentingViewController.providesPresentationContextTransitionStyle = YES;
self.presentingViewController.definesPresentationContext = YES;
modal.modalPresentationStyle = UIModalPresentationOverCurrentContext;
Run Code Online (Sandbox Code Playgroud)
我在哪里放这个代码?
joe*_*ern 260
你可以这样做:
在主视图控制器中:
func showModal() {
let modalViewController = ModalViewController()
modalViewController.modalPresentationStyle = .overCurrentContext
presentViewController(modalViewController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
在你的模态视图控制器中:
class ModalViewController: UIViewController {
override func viewDidLoad() {
view.backgroundColor = UIColor.clearColor()
view.opaque = false
}
}
Run Code Online (Sandbox Code Playgroud)
如果您正在使用故事板:
只是增加一个故事板Segue公司Kind设置为Present Modally你的模式视图控制器,并设置下列值这个视图控制器:
正如Crashalot在他的评论中所指出的那样:确保segue仅Default用于Presentation和Transition.使用Current Contextfor Presentation使模态变为黑色而不是保持透明.
| 归档时间: |
|
| 查看次数: |
117227 次 |
| 最近记录: |