如何解决每次我进入不同的 UIcontrolview swift 时都会有额外的视图层
这是第一个,正常没有问题
每次进入新视图时都会有一个额外的图层。
你可以看到它每次都在增加
每当我在 xcode 上转到不同的视图时,都会有一个工具栏大小的图层挡住我的视图,我是 swift 的新手,所以如果我没有使用正确的术语,我很抱歉,但任何人都可以请帮我解决这个问题?
这是我用来切换视图的代码
let register = UIStoryboard(name: "RegisterEmail",bundle: nil)
let controller =register.instantiateViewController(identifier:"RegisterEmail") as! RegisterEmail
let navigation = UINavigationController(rootViewController:controller)
self.view.addSubview(navigation.view)
self.addChild(navigation)
navigation.didMove(toParent: self)
编辑(解决了问题)但是
let storyboard = UIStoryboard(name: "ForgotPassword",bundle: nil)
let secondViewController = storyboard.instantiateViewController(withIdentifier: "ForgotPassword") as! ForgotPassword
self.navigationController?.pushViewController(secondViewController,animated: true)
不起作用,有什么帮助吗?
解决方法
看起来您正在当前导航堆栈中添加一个新的导航堆栈,这应该是您在视图中拥有新导航栏的原因。您应该只推送或显示视图。
,就像上一个答案所说的,您不断向 viewController 的视图添加 UINavigationController
视图。我相信您已经在故事板中添加了 UINavigationController
,因此,要抓取它,只需使用 self.navigationController
。您不需要创建一个新的并将其添加到 viewStack。它已经展示了您当前的 VC。
我无法理解你想要达到的目标。如果您希望每个视图都有自己的 VC,那么第二个代码片段中的代码应该可以工作 - 如果您在故事板中创建了三个 viewController。但是,从第一个代码片段来看,您似乎要添加三个子视图控制器。如果是这种情况,请将代码片段更改为
let storyboard = UIStoryboard(name: "ForgotPassword",bundle: nil)
let childVC = storyboard.instantiateViewController(withIdentifier: "ForgotPassword") as! ForgotPassword
addChild(childVC)
childVC.view.frame = frame
view.addSubview(childVC.view)
childVC.didMove(toParent: self)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。