【问题标题】:PageViewController makes my PickerView not appearPageViewController 使我的 PickerView 不出现
【发布时间】:2016-08-26 13:25:07
【问题描述】:

我在情节提要中有 2 个 ViewController,RootViewControllerDetailViewController。在DetailViewController 我的标签和其他东西进去了。

RootViewController 中,我向UIPageViewController 添加了几个 ViewController,因此我可以水平滚动。

问题是当我将UIPickerView 添加到我的RootViewController 并且在我运行应用程序时不显示。

我在 Xcode 中创建了基于页面的应用程序来玩 PageViewController。通过创建项目,会出现一堆默认代码。 我希望这能说明我的问题。

override func viewDidLoad() {
    self.pickerView = UIPickerView()
    self.pickerView?.delegate = self
    self.pickerView?.hidden = false

    // Configure the page view controller and add it as a child view controller.
    self.pageViewController = UIPageViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)
    self.pageViewController!.delegate = self

    let startingViewController: DataViewController = self.modelController.viewControllerAtIndex(0, storyboard: self.storyboard!)!

    let viewControllers = [startingViewController]
    self.pageViewController!.setViewControllers(viewControllers, direction: .Forward, animated: false, completion: {done in })

    self.pageViewController!.dataSource = self.modelController

    self.addChildViewController(self.pageViewController!)
    self.view.addSubview(self.pageViewController!.view)

    // Set the page view controller's bounds using an inset rect so that self's view is visible around the edges of the pages.
    var pageViewRect = self.view.bounds.offsetBy(dx: CGFloat(0), dy: CGFloat(45))
    if UIDevice.currentDevice().userInterfaceIdiom == .Pad {

        pageViewRect = CGRectInset(pageViewRect, 40.0, 40.0)
    }
    self.pageViewController!.view.frame = pageViewRect

    self.pageViewController!.didMoveToParentViewController(self)
}

【问题讨论】:

    标签: ios swift uipageviewcontroller


    【解决方案1】:

    使用bringSubviewToFront试试这个。它可能对你有帮助

    [parentView 带来SubviewToFront:childView];

    在斯威夫特中

    parentView.bringSubviewToFront(childView)

    喜欢: parentView.bringSubviewToFront(self.pickerView)

    【讨论】:

    • 试过了,但没有用。 I have added a Button Action on the screen and whenever its tapped it should show the PickerView and when a row is selected the PickerView should disappear.
    • 如何访问 parentView?我的项目中不存在该对象。
    • self.superview 试试这个
    • 那不存在。我使用了 self.parentViewController.view.bringSubviewToFront(self.pickerView) 但不起作用。
    【解决方案2】:

    将 UIPickerView 添加到您的控制器视图并设置 UIPickerView 框架。

    let pickerView = UIPickerView(frame: yourFrame)
    pickerView.dataSource = self
    pickerView.delegate = self
    
    controller.view.addSubview(pickerView)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-17
      • 1970-01-01
      相关资源
      最近更新 更多