【问题标题】:why is my view all black after initiating a simple "performSegueWithIdentifier"?为什么在启动一个简单的“performSegueWithIdentifier”后我的视图全是黑色的?
【发布时间】:2015-09-11 02:34:33
【问题描述】:

我只是试图以编程方式启动一个简单的 segue,但由于某种原因,当我这样做时,目标视图全黑,当我通过导航控制器返回时,它会改变我的其余视图黑色也一样。这是我的 IB 中的转场:

这是segue的代码,通过主控制器中的一个按钮:

@IBAction func buttonPressed(sender: AnyObject) {

        self.performSegueWithIdentifier("showLoading", sender: self)
    }

但是,当我运行应用程序并按下按钮时,segue 工作但视图只是黑色:

之前的每个视图也是黑色的。但是我每次在选项卡之间来回切换时都会注意到,视图是常规的,而不是这个黑屏。为什么会出现这种异常行为?

【问题讨论】:

  • 你给那个控制器分配了一个类
  • 我在您的屏幕截图中看到一个视图具有深色背景。可能是继承问题?使用导航控制器,后续视图会继承导航控制器的颜色。这是我可以复制您所描述的内容的唯一方法
  • 不,那只是该视图中 uiimageview 的图像。它的背景。 @RMenke
  • 我从中发送 segue 的视图不是在 IB 中手动连接的,它是在以前的视图中实例化的,那会有什么不同吗? @RMenke
  • 我从中发送 segue 的视图不是在 IB 中手动连接的,它是在以前的视图中实例化的,那会有什么不同吗? @拉马尔

标签: ios xcode swift uiview segue


【解决方案1】:

一旦我禁用了故事板的 sizeclass。

将popover segue之一更改为push segue。

然后我启用sizeclass,这个segue和你在storyboard中的一样,问题也是。

在我将这个 segue 改回 popover segue 后,一切都恢复正常了。

这就是我解决这个问题的方法,但我不知道为什么。

以下是我在presentedviewcontroller中的代码:

    // MARK: - Navigation

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
 if segue.identifier == Constants.EditWaypointSegue {
        if let waypoint = (sender as? MKAnnotationView)?.annotation as? EditableWaypoint {
            if let ewvc = segue.destinationViewController.contentViewController as? EditWaypointViewController {
                if let ppc = ewvc.popoverPresentationController {
                    let coordinatePoint = mapView.convertCoordinate(waypoint.coordinate, toPointToView: mapView)
                    ppc.sourceRect = (sender as! MKAnnotationView).popoverSourceRectForCoordinatePoint(coordinatePoint)
                    let minimumSize = ewvc.view.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize)
                    ewvc.preferredContentSize = CGSize(width: Constants.EditWaypointPopoverWidth, height: minimumSize.height)
                    ppc.delegate = self
                }
                ewvc.waypointToEdit = waypoint
            }
        }
    }
}

// MARK: - UIAdaptivePresentationControllerDelegate

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
    println("full")
    return UIModalPresentationStyle.FullScreen // full screen, but we can see what's underneath
}
func presentationController(controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController?
{
    let navcon = UINavigationController(rootViewController: controller.presentedViewController)
    let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .ExtraLight))
    visualEffectView.frame = navcon.view.bounds
    navcon.view.insertSubview(visualEffectView, atIndex: 0) // "back-most" subview
    return navcon
}

【讨论】:

  • 我的故事板中没有弹出框转场
  • @MikeStrong 我把代码贴出来,以防有人在其中发现了什么。你应该尝试删除 segue,然后重新创建它,看看会发生什么。
猜你喜欢
  • 1970-01-01
  • 2016-07-22
  • 1970-01-01
  • 2019-04-26
  • 2014-07-28
  • 2021-04-11
  • 1970-01-01
  • 1970-01-01
  • 2017-09-18
相关资源
最近更新 更多